You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Analyzer warning and quick fix for ToDictionary over GroupBy #16838
We've had discussions in #16730 and offline about the following:
vartest=awaitthis.dbcontext.MyEntity.GroupBy(x =>x.Status).ToDictionary(x =>x.Key.Name, y =>y.Count());
There is evidence to support that a common expectation is for this to get translated for server evaluation. However, since ToDictionary() is only defined over IEnumerable, EF Core cannot see the aggregate function and the grouping will in fact be performed client-side.
We can have an analyzer to detect this, and even suggest a quick fix of extracting the aggregate lambda inserting a Select() with it between the GroupBy and ToDictionary.
Reacted by Shane Krueger, Arad Alvand, Piyash Khanal and KLuuKer
I would love to see such an analyzer, we just fell into this trap and it was a pain to diagnose. Especially for ToDictionaryAsync since it comes from EF.Core.
Activity
divega commentedon Jul 31, 2019
The analyzer should probably recognize
ToLookupas well.molinch commentedon Aug 5, 2024
I would love to see such an analyzer, we just fell into this trap and it was a pain to diagnose. Especially for ToDictionaryAsync since it comes from EF.Core.
roji commentedon Aug 5, 2024
Reopening to reconsider doing this, now that we're starting to have static analysis capabilities for EF LINQ queries (via precompiled queries).