-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DefaultIfEmpty throwing ArgumentOutOfRangeException #7830
Comments
@gnaungayan try the following:
Currently, SelectMany-GroupJoin_DefaultIfEmpty pattern is the way to model LEFT JOIN in EF Core. You are seeing INNER JOIN for the second navigation, because that JOIN comes from navigation rewrite. In the rewrite we look at the navigation metadata itself to determine whether it should be optional or requited, and in your case navigation OrganizationUser -> Organization is required. For cases when navigation expansion is used from the start, we "propagate" the optional navigation, so:
|
@maumar Thanks for the alternative query although unnecessary columns are being selected despite the projection, I guess this is another bug? I also notice that using this query which is basically the same you gave produces a different SQL Query. It also noted that the below query will use CASE-WHEN pattern compared to the above query
|
@gnaungayan additional columns are projected due to #6647. This issue has been fixed so this shouldn't be happening in the next version. The second query produces different SQL because EF Core (unlike EF6) doesn't recognize the from from-from-where-defaultifempty pattern as LEFT JOIN and so it will perform naive translation. We have issue to track the improvement for this here - #7887 |
Closing this - tracking improvement to the null propagation in separate issue: #7975 |
If I call on DefaultIfEmpty (to make a left join), EF throws an ArgumentOutOfRangeException but removing it fixes the issue though not producing the desired result. The code is working fine on EF6.
Querying directly to the "Join" class produce a left join to that class and an inner join to the Organisation table (should be left join as well).
Scenario
The list should display all users regardless if it has an organisation or not.
DbSets:
DbContext:
Query:
SQL Produced
Exception Message:
Stack trace:
Further technical details
EF Core version: Microsoft.EntityFrameworkCore 1.1.1
Database Provider: Microsoft.EntityFrameworkCore.SqlServer 1.1.1
Operating system: Windows 10
IDE: Visual Studio 2015
The text was updated successfully, but these errors were encountered: