dotnet / efcore

EF Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations.
https://docs.microsoft.com/ef/
MIT License
13.8k stars 3.19k forks source link

Translate LINQ CountBy #32741

Open manandre opened 10 months ago

manandre commented 10 months ago

.NET 9.0 will introduce CountBy, which we could translate.

CountBy can be rewritten as follows:

_ = blogs.CountBy(b => b.Id);
_ = blogs.GroupBy(b => b.Id).Select(g => KeyValuePair.Create(g.Key, g => g.Count()));

This feature could be part of the epic https://github.com/dotnet/efcore/issues/25570

roji commented 10 months ago

Thanks @manandre, makes sense! Added to the epic.