EF Core's
GroupBy
support is notoriously bad.
Something like this
might work:
context.Categories
.SelectMany(c => c.StaticEvents)
.GroupBy(c => c.Time.Month, (month, items) => new {
Month = month,
Categories = items.GroupBy(i => i.CategoryId, (key, m) => new { Sub = key, Score = m.Count() })
}).ToList();
However, given the large number of
GroupBy
issues logged on the EF Core GitHub repo, there are no guarantees.
Issues · dotnet/efcore · GitHub[
^]
You might end up having to execute a raw SQL query instead.