分组加入EF Core 3.1 [英] Group join in EF Core 3.1
问题描述
我正在尝试将EF core 3.1组加入
I am trying to group join in EF core 3.1 the problem it returns
LINQ表达式'DbSet的处理失败.这可能表示EF核心存在错误或局限性
Processing of the LINQ expression 'DbSet failed. This may indicate either a bug or a limitation in EF Core
我的代码就是这样
var employees = await (from enrollment in RepositoryContext.Enrollments
join allowance in RepositoryContext.Allowances.Include(y=>y.AllowanceType) on enrollment.EmployeeId equals allowance.EmployeeId
into allowances
select new
{
enrollment,
allowances
}
).AsNoTracking().ToListAsync();
津贴是项目列表, 是否有任何变通办法可以像这样运行查询,因为我需要它以获得更好的性能.
the allowances is list of items , is there any workaround to run the query like this cause i need it for better berformance.
推荐答案
在使用GroupBy进行查询或GroupJoin引发异常是现在已关闭的GitHub问题/讨论,我试图说服EF Core团队添加GroupJoin
翻译.他们拒绝这样做,并打开了无用的查询:当它是最终查询运算符#19930时,支持GroupJoin 我继续为这种翻译而战.因此,请转到此处并对完整的翻译请求进行评论/投票.
Here Query with GroupBy or GroupJoin throws exception is the now closed GitHub issue/discussion where I was trying to convince EF Core team to add GroupJoin
translation. They refused to do that and opened the useless Query: Support GroupJoin when it is final query operator #19930 where I continue the fight for such translation. So please go there and comment/vote up for the full translation request.
您还将在此处找到解决方法-而不是不受支持的GroupJoin
使用等效的受支持的相关子查询方法,例如替换
You will also find there the workaround - instead of unsupported GroupJoin
use the equivalent supported correlated subquery approach, e.g. replace
join allowance in RepositoryContext.Allowances.Include(y => y.AllowanceType)
on enrollment.EmployeeId equals allowance.EmployeeId
into allowances
使用
let allowances = RepositoryContext.Allowances.Include(y => y.AllowanceType)
.Where(allowance => enrollment.EmployeeId == allowance.EmployeeId)
这篇关于分组加入EF Core 3.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!