下面是运行在EF7 Beta 8上的代码:
var locationGrops = from l in db.Locations
group l by l.ServiceType into g
select g;
var list = locationGrops.ToList();执行此代码时,EF将显示警告。
warning : [Microsoft.Data.Entity.Query.QueryCompilationContext] The LINQ express
ion 'GroupBy([l].ServiceType, [l])' could not be translated and will be evaluate
d locally.在我看来,这个查询是非常基本的,在SQL中有GROUP。有没有办法让它在服务器上运行?
发布于 2015-10-22 04:52:21
此时,group by和大多数子查询都不受EF7支持。
发布于 2015-10-26 23:45:11
您可以使用context.Locations.FromSql(sql).ToList()确保您的查询在服务器上按需要运行。
发布于 2016-05-27 01:49:25
一种方法是使用逻辑创建数据库视图(对于复杂分组来说,这可能更好)。
现在,使用视图有点麻烦,但如果您使用脚手架,下面是我想出的方法:
How can I create database Views in a scaffolded DbContext in EF7 / Entity Framework Core 1.0
总之,我继承了DbContext,并手动为视图创建实体类。
https://stackoverflow.com/questions/33266588
复制相似问题