EF7 and GroupBy() cannot be translated

asp.net-core-mvc entity-framework-core

Question

I have following code running on EF7 Beta 8:

var locationGrops = from l in db.Locations
                    group l by l.ServiceType into g
                    select g;

var list = locationGrops.ToList();

When I execute this code, EF displays a warning.

warning : [Microsoft.Data.Entity.Query.QueryCompilationContext] The LINQ express
ion 'GroupBy([l].ServiceType, [l])' could not be translated and will be evaluate
d locally.

The query seems quite basic to me and there is GROUP BY in SQL. Is there any way to make it run on a server?

Accepted Answer

At this time group by and and most subqueries are not supported by EF7.


Popular Answer

You can use context.Locations.FromSql(sql).ToList() to ensure your query is run as you desire on the server.



Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why