Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EF7 and GroupBy() cannot be translated

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?

like image 210
Sergey Kandaurov Avatar asked Oct 21 '15 18:10

Sergey Kandaurov


2 Answers

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

like image 29
natemcmaster Avatar answered Dec 26 '22 07:12

natemcmaster


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

like image 141
Dmitry S. Avatar answered Dec 26 '22 07:12

Dmitry S.