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;
    }

存储过程:

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 

无法弄清楚如何从列表中获取项目计数。

不是:AppCache 等价于 App

4

1 回答 1

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() }
于 2013-10-14T19:27:25.920 回答