不支持客户端 GroupBy [英] Client side GroupBy is not supported
问题描述
我有以下 Entity Framework Core 3.0 查询:
I have the following Entity Framework Core 3.0 query:
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));
我收到以下错误:
Client side GroupBy is not supported.
要在客户端或部分客户端上运行查询,我将执行以下操作:
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));
现在可以了.
如果我没有在客户端上运行查询,为什么会出现此错误?
Why am I getting this error if I am not running the query on the client?
推荐答案
Your .GroupBy(y => y.LanguageCode).ToDictionaryAsync(y => y.Key, y => y.Select(z => z.Name));
无法转换为 SQL.EF Core 3.0 将抛出异常以确保您知道 Units
中的所有记录将在分组并映射到字典之前从数据库中获取.
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.
这是 EF Core 3.0 中最重大的变化.https://docs.microsoft.com/en-us/ef/core/what-is-new/ef-core-3.0/break-changes
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
这篇关于不支持客户端 GroupBy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!