Use LINQ CountBy()

Proprietary

Replace collection.GroupBy(selector).Select(g => g.Count()) with collection.CountBy(selector). Available since .NET 9.

OpenRewrite.Recipes.CSharp.Migration.Dotnet.Net9.UseLinqCountBy
mod run . --recipe=OpenRewrite.Recipes.CSharp.Migration.Dotnet.Net9.UseLinqCountBy

Install it once, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.