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
Query: [Nav Prop Translation] EF7 generating incorrect sql with optional relationships #4205
Comments
So I believe this is related to #3186 |
|
@rowanmiller #3703 is done and the LOJ issue is being tracked in #3186. So I believe we should close this? |
@maumar anything you want to track on this issue... or is it good to be closed now (feel free to close if you are happy it's all covered). |
I will keep it open for now to make sure that this specific case works (complex projection with navigations like that) |
👍 |
Just to add to this, I noticed similar problems occur even in the context.News
.Select(dto => new NewsDto()
{
Id = dto.Id,
Title = dto.Title,
Branch = dto.Branch == null ? null : new BranchDto()
{
Id = dto.Branch.Id,
Name = dto.Branch.Name
}
}).ToList(); do not work as expected (return null). So I guess a part of this is rooted in the common code and not something specific to the sql provider. |
@mrahhal That is correct, navigation translation is done in the common part of the query pipeline - currently we always translate navigations into a LINQ join, which in memory have semantics of INNER JOIN and in relational get translated to INNER JOIN directly. The fix we are currently working on will translate optional navigations into SelectMany-GroupJoin-DefaultIfEmpty construct which behaves like LOJ |
Fixed in c4e4447 |
Consider the following models:
Here we have an optional relationship between
News
andBranch
(1-to-many).We're issuing the following query:
EF6
The generated query is:
This is how it should be: a left outer join after a
CASE WHEN
to handle null references to theBranches
table.EF7 (RC1)
The same query is generated as:
I don't really understand why this is happening. The relationship is clearly optional so inner joins are just plain wrong. Other than that, the line
[dto].[BranchId] IS NULL
is giving aSystem.Data.SqlClient.SqlException: Incorrect syntax near the keyword 'IS'
so I guess this isn't even valid sql.This is only happening when the relationship is optional.
The text was updated successfully, but these errors were encountered: