Problem with return type of group join in C#

c# ef-core-3.1 entity-framework-core linq

Question

I have 2 tables (Questions and Answers) each question may have several answers or none. I need return a list of questions with answers of them. I tried to do it but unfortunately the error message below is shown.

Processing of the LINQ expression 'code below' by 'NavigationExpandingExpressionVisitor' failed. This may indicate either a bug or a limitation in EF Core. See https://go.microsoft.com/fwlink/?linkid=2101433 for more detailed information."

I think code below is going to demonstrate my problem.

        _dataContext.Questions.GroupJoin(_dataContext.Answers, r => r.Id, s => s.QuestionId, (r, s) => new QuestionWithAnswerResult()
        {
            Description = r.Description,
            EvaluationOrder = r.EvaluationOrder,
            EvaluationType = r.EvaluationType,
            Id = r.Id,
            IsActive = r.IsActive,
            Order = r.Order,
            Answers = s.Select(answer => new AnswerResult()
            {
                Id = answer.Id,
                Response = answer.Response
            }).ToList()
        }).ToList();

Please help me to solve this issue.

1
0
4/16/2020 1:14:07 PM

Accepted Answer

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)
1
4/16/2020 1:13:20 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow