Group join in EF Core 3.1

冷暖自知 提交于 2020-08-19 07:29:29

问题


I am trying to group join in EF core 3.1 the problem it returns

Processing of the LINQ expression 'DbSet failed. This may indicate either a bug or a limitation in EF Core

my code is like this

 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.


回答1:


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.

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

with

let allowances = RepositoryContext.Allowances.Include(y => y.AllowanceType)
    .Where(allowance => enrollment.EmployeeId == allowance.EmployeeId)


来源:https://stackoverflow.com/questions/60588364/group-join-in-ef-core-3-1

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!