I'm trying to run the following code but when I check the SQL profiler it looks like it runs a full select on the table and then does the grouping after it returns all 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();
The GROUP BY statement is usually used (mostly with aggregate functions) to group the result of your query by one or more columns.
Highly requested featuresJSON columns: Save and query into JSON-based documents stored in relational database columns. Bulk updates: Efficient, predicate-based updates for many database rows without loading data into memory. Lifecycle hooks: Allow applications to react when interesting things happen in EF code.
EF Core already supports querying data from stored procedures. This feature will allow mapping the inserts, updates, and deletes generated by SaveChanges to stored procedures in the database.
Entity Framework (EF) Core is a lightweight, extensible, open source and cross-platform version of the popular Entity Framework data access technology. EF Core can serve as an object-relational mapper (O/RM), which: Enables . NET developers to work with a database using .
The issue linked below has been closed, and it is slated for EF 2.1.0. You should be able to try it out now using the Preview package!
It doesn't look like this is currently supported, but it looks like someone saw this post and created the linked issue.
The concept is a fairly complex bit of logic, and EF7 is very much in an early phase. .Net's GroupBy
doesn't translate directly to SQL's GROUP BY
until you follow it up with only aggregates or the Key in a Select
. If you're feeling ambitious, you could work on providing a pull request, or continue to use EF6.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With