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

最佳答案

这应该是您存储过程的翻译。如果要返回其他内容,只需修改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() }

关于c# - 将存储过程转换为LINQ查询,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19366715/

10-13 00:50