I started with this query:
var results =
context.Set<Record>()
.GroupBy(r => r.Number)
.Select(g => new { g.Key, Count = g.Count() })
.ToList();
Whilst refactoring I extracted this query into a method so the GroupBy takes a delegate. This change has resulted in the aggregation now being carried out in memory.
Is this behaviour by design? I've just lost out on benefits of aggregating in SQL.
Here's an example of the in-memory aggregation:
Func<Record, int> func = r => r.Number;
var results =
context.Set<Record>()
.GroupBy(func)
.Select(g => new { g.Key, Count = g.Count() })
.ToList();