-
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
Query: [Nav Prop Translation] EF can't join between same types if one of them is queryed inside the expression #3141
Comments
@Suchiman Thanks for reporting this. What version exactly are you using? |
Built from 2553a0c but no custom modifications |
This is a dupe of #113 |
@rowanmiller x.User.Id == context.Nicknames.FirstOrDefault(n => n.Name == nickname).User.Id results in: SELECT "post"."PostId", "post"."UserUserId", "post.User"."UserId"
FROM "Post" AS "post"
INNER JOIN "User" AS "post.User" ON "post"."UserUserId" = "post.User"."UserId" The filter is lost. Also i wanted to point out that EF6 didn't support comparison of entities in queries to local instances but against other entities in the same queries as per my sample code. SELECT
1 AS "C1",
"Extent1"."PostId" AS "PostId",
"Extent1"."User_UserId" AS "User_UserId"
FROM "Posts" AS "Extent1"
LEFT OUTER JOIN (SELECT
"Extent2"."User_UserId" AS "User_UserId"
FROM "Names" AS "Extent2"
WHERE ("Extent2"."Text" = @p__linq__0) OR (("Extent2"."Text" IS NULL) AND (@p__linq__0 IS NULL)) LIMIT 1 ) AS "Project1" ON 1 = 1
LEFT OUTER JOIN "Users" AS "Extent3" ON "Project1"."User_UserId" = "Extent3"."UserId"
WHERE ("Extent1"."User_UserId" = "Extent3"."UserId") OR (("Extent1"."User_UserId" IS NULL) AND ("Extent3"."UserId" IS NULL)) |
Need to investigate the dropping of the filter mentioned in above comment |
Reassigning to @anpete since he already started working on the general issue |
@mikary can you let us know what you find, then we can re-triage |
Ran the original repro and it now throws a using (var context = new TestContext())
{
Post postOfUserTest = context.Posts
.FirstOrDefault(post => post.User.UserId == context.Names
.FirstOrDefault(name => name.Text == "Test").User.UserId);
} |
works in current bits, closing |
Well 😐 ... works enough to work but not enough to be useful in any way. Loading the entire table into memory to find a single user is... not webscale 😛
SELECT "post"."PostId", "post"."UserId", "post.User"."UserId"
FROM "Posts" AS "post"
LEFT JOIN "Users" AS "post.User" ON "post"."UserId" = "post.User"."UserId"
ORDER BY "post"."UserId"
SELECT "name"."NameId", "name"."Text", "name"."UserId", "name.User"."UserId"
FROM "Names" AS "name"
LEFT JOIN "Users" AS "name.User" ON "name"."UserId" = "name.User"."UserId"
WHERE "name"."Text" = 'Test'
ORDER BY "name"."UserId" Is this the most inefficient SQL contest?... doing a left join which doesn't constrains the result set and without selecting from the join and then doing a second query with exactly the reverse statement, only cross apply could make it worse. |
@maumar is there already another issue tracking the client eval aspect of this? |
@rowanmiller @Suchiman yes, we track it here: #4588 |
Sorry for the bad title, i have no idea how to describe it.
Try running following Code
It will crash with
The text was updated successfully, but these errors were encountered: