I have the following Entity Framework Core 3.0:
var units = await context.Units
.SelectMany(y => y.UnitsI18N)
.OrderBy(y => y.Name)
.GroupBy(y => y.LanguageCode)
.ToDictionaryAsync(y => y.Key, y => y.Select(z => z.Name));
And I get the following error:
Client side GroupBy is not supported.
Why am I getting this error if I am not running the query on the client?
To run the query on the client, or part of it, I would do the following:
var units = context.Units
.SelectMany(y => y.UnitsI18N)
.OrderBy(y => y.Name)
.AsEnumerable()
.GroupBy(y => y.LanguageCode)
.ToDictionary(y => y.Key, y => y.Select(z => z.Name));
Now it works ...
Your .GroupBy(y => y.LanguageCode).ToDictionaryAsync(y => y.Key, y => y.Select(z => z.Name));
cannot be converted to SQL.
EF Core 3.0 will throw exception to make sure you know that all records in Units
will be fetched from database before grouping and map to Dictionary.
It's top breaking change in EF Core 3.0. https://docs.microsoft.com/en-us/ef/core/what-is-new/ef-core-3.0/breaking-changes
Apparently it's not yet supported in EF Core 3.0, that is, it is not supported to perform GroupBy
over SQL.
One possible solution (works for me) is to make the GroupBy
on a List
object.
var units = (
await context.Units
.SelectMany(y => y.UnitsI18N)
.GroupBy(y => y.LanguageCode)
.ToDictionaryAsync(y => y.Key, y => y.Select(z => z.Name))
).ToList().OrderBy(y => y.Name);
来源:https://stackoverflow.com/questions/58138556/client-side-groupby-is-not-supported