2013-10-14 115 views
2
public static IEnumerable<AppCache> GetTopRatedApps(string language,bool isinitialized) 
    { 
     List<AppCache> objApps = new List<AppCache>(); 

     objApps = GetAllApps(isinitialized,language).ToList(); 

     List<RatingCache> objRatings = new List<RatingCache>(); 

     objRatings = GetAllRatings(); 

      var query = 
    from Apps in objApps 
    join ratings in objRatings 
     on Apps.AppId equals ratings.AppId where ratings.RatingGiven == 1 
    select new AppCache(); 

     return query; 
    } 

存儲過程:轉換存儲過程LINQ查詢

select o.AppId, count(*) as ItemCount 
from App o 
inner join Rating od 
    on o.AppId = od.AppId 
where od.RatingGiven = 1 
group by o.AppId 

無法弄清楚如何獲得該項目從列表中計數。

不是:應用程序緩存相當於應用

+1

是否'group'幫助http://msdn.microsoft.com/en-us/library/bb545971.aspx – Harrison

+0

也,看看LINQ做了一些樣本分組:HTTP://code.msdn。 microsoft.com/LINQ-to-DataSets-Grouping-c62703ea – GolfWolf

+0

這裏是一個帖子,顯示你正在尋找什麼http://stackoverflow.com/a/10047966/2145211 – Harrison

回答

2

這應該是你的存儲過程的翻譯。如果你想返回別的東西,只需修改select方法。

var query = from Apps in objApps 
      join ratings in objRatings 
       on Apps.AppId equals ratings.AppId 
      where ratings.RatingGiven == 1 
      group Apps by Apps.AppId into g 
      select new { AppId = g.AppId, ItemCount = g.Count() }