Entity Framework Group 7 by

I am trying to run the following code, but when I check the SQL profiler, it looks like it makes a full selection in the table and then groups it after it returns all the results from the database. Any help is appreciated.

var result = _dbContext.LogEvent.GroupBy(x => x.EventLevel) .Select(g => new { eventType = g.Key, total = g.Sum(i => i.Occurrences) }) .ToList(); 
+7
asp.net-core asp.net-core-mvc entity-framework-core
source share
2 answers

This doesn't seem to be supported at the moment , but it looks like someone saw this message and created a related issue.

The concept is a rather complicated cue ballgame of logic, and EF7 is at an early stage GroupBy Net GroupBy does not translate directly to SQL GROUP BY until you execute it only with aggregates or key in Select . If you feel ambitious, you can work on submitting a stretch request, or continue to use EF6.

+7
source share

Most likely, it will not be supported in the near future - unfortunatelt. This leads to great disappointment, as many people do not read the release notes, and it is only natural to assume that it will work as before (EF6 / Linq2SQL).

I understand that it can be complicated for more complex things related to whole entities, but it’s a shame that it is not even supported for simple queries like yours :-(

https://blogs.msdn.microsoft.com/dotnet/2016/05/16/announcing-entity-framework-core-rc2/

0
source share

All Articles