You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am currently writing an EntityFramework Provider. While translating the expression produced by NorthwindSelectQueryTestBase.SelectMany_correlated_with_outer_3, I noticed that the NavigationExpandingExpressionVisitor moves the .Select(o => c.City) behind the .DefaultIfEmpty().
I'm probably missing something, but this seems wrong, as
Enumerable.Empty().DefaultIfEmpty().Select(x => "foo")
is not the same as
Enumerable.Empty().Select(x => "foo").DefaultIfEmpty()
So now I'm left wondering how to handle this, because there are valid uses for both cases. Once the NavigationExpandingExpressionVisitor transforms the expression however I can no longer distinguish between these cases.
I would be very thankful if you could give me some pointers on what the actual behaviour should be.
Best Regards
Your code
NorthwindSelectQueryTestBase.SelectMany_correlated_with_outer_3:fromcinss.Set<Customer>()fromoinss.Set<Order>().Where(o =>c.CustomerID==o.CustomerID).Select(o =>c.City).DefaultIfEmpty()selectnew{c,o}
Here's what the query looks like just before and after the call to the NavigationExpandingExpressionVisitor inQueryTranslationPreprocessor.csProcess(Expressionquery)
Before NavigationExpandingExpressionVisitor:[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].SelectMany(c =>[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].Where(o =>(c.CustomerID==o.CustomerID)).Select(o =>c.City).DefaultIfEmpty(),(c,o)=>new<>f__AnonymousType0`2(c=c,o=o))
After NavigationExpandingExpressionVisitor:[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].SelectMany(c =>[Microsoft.EntityFrameworkCore.Query.EntityQueryRootExpression].Where(o =>(c.CustomerID==o.CustomerID)).DefaultIfEmpty().Select(o =>c.City),(c,c)=>newTransparentIdentifier`2(Outer=c,Inner=c)).Select(ti =>new<>f__AnonymousType0`2(c=ti.Outer,o=ti.Inner))
Activity
roji commentedon Jun 9, 2025
Thanks, this indeed looks like a bug in EF itself (in NavigationExpandingExpressionVisitor).
Minimal repro
Stop moving pending selector after DefaultIfEmpty in nav expansion
Stop moving pending selector after DefaultIfEmpty in nav expansion
Stop moving pending selector after DefaultIfEmpty in nav expansion
Stop moving pending selector after DefaultIfEmpty in nav expansion
Stop moving pending selector after DefaultIfEmpty in nav expansion
Stop moving pending selector after DefaultIfEmpty in nav expansion (#β¦