“PaginatedReport”类有两个成员:
int TotalResults;
IList<Report> Reports;
我尝试使用此查询填充此类的实例:
var reports = (from r in _db.Report
where r.res_id == status
group r by r.res_id into g
select new PaginatedReport
{
TotalResults = g.Count(),
Reports = g.OrderBy(x =>x.res_id).Skip(start).Take(nb).ToList()
});
如何更正查询以避免以下错误:
Linq to entitites无法识别方法“System.Collections.Generic.List 1[DAL.Report]
ToList[Report](System.Collections.Generic.IEnumerable
1 [DAL.Report])”,并且此方法无法转换为商店。
答案 0 :(得分:0)
您需要在本地执行最后一步(Select
返回匿名类型),而不是让LINQ提供程序尝试将其转换为(可能是)SQL。类似的东西:
var reports = from g in (from r in _db.Report
where r.res_id == status
group r by r.res_id).AsEnumerable()
select new PaginatedReport {
TotalResults = g.Count(),
Reports = g.OrderBy(x =>x.res_id).Skip(start).Take(nb).ToList()
};
(并且整个表达式周围不需要括号)。