-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Erroneous warning "The Include operation for navigation was ignored" #7153
Comments
@mguinness You only need to use var customersWithState = ctx.Customers.Include(c => c.State).Select(c => c).ToList(); Or for short: var customersWithState = ctx.Customers.Include(c => c.State).ToList(); In your query you are explicitly projecting individual scalar properties |
I am going to leave this bug open however because there are a few unexpected (for me) things showing up in the query plan. I want to make sure this is a query we have optimized further in 1.1. |
SQL output for 1.1 is as follows (with or without the call to SELECT "c"."CustomerId", "c"."CustomerName", "c"."StateId", "c.State"."StateId", "c.State"."Abbreviation", "c.State"."StateName"
FROM "Customers" AS "c"
LEFT JOIN "States" AS "c.State" ON "c"."StateId" = "c.State"."StateId"
ORDER BY "c"."StateId" |
@divega Thanks for explaining, that helps my understanding. It appears that I wasn't the only one caught out regarding this (see issue #7144). Maybe a minor text change to the warning would help? The Include operation for navigation: 'c.State' is unnecessary and was ignored because the target navigation is not reachable in the final query results. |
Split off a new issue to improve the docs - #7162 |
@divega I did try removing the
SELECT "c"."CustomerId", "c"."CustomerName", "c"."StateId", "c.State"."StateId", "c.State"."Abbreviation", "c.State"."StateName"
FROM "Customers" AS "c"
LEFT JOIN "States" AS "c.State" ON "c"."StateId" = "c.State"."StateId"
ORDER BY "c"."StateId" Got warning I would have expected the following SQL, do I need to compose the query differently? SELECT "c"."CustomerId", "c"."CustomerName", "c"."StateId", "c.State"."StateId", "c.State"."Abbreviation", "c.State"."StateName"
FROM "Customers" AS "c"
LEFT JOIN "States" AS "c.State" ON "c"."StateId" = "c.State"."StateId"
WHERE "c.State"."Abbreviation" = 'WA'
ORDER BY "c"."StateId" |
I think this is still an issue. I'm getting the erroneous warning by doing the following: Steps to reproduce//Simplified code...
IQueryable<ProductRequest> data = dataContext.ProductRequests
.Include(r => r.Customer)
.Where(c => !c.Deleted);
//Other dynamic filters...
return Ok(data.ToList()); The navigation property is not actually ignored. I get the desired output which means I can see the customer object serialized in the final payload. The issueI just want the 'customer' property to be populated when each item is serialized, so I added the So I should see the warning only if I do Further technical detailsMicrosoft.AspNetCore.All 2.0.5 @divega @rowanmiller Can this issue be re-opened ? |
@kgKevGomez - I ran above query and did not get any warning that include was ignored. Please file a new issue with repro code showing the issue you are seeing. |
Steps to reproduce
Attached is ConsoleApp2.zip which demonstrates the issue.
The issue
When running the following code, the warning "The Include operation for navigation: 'c.State' was ignored because the target navigation is not reachable in the final query results." is shown, but it makes no sense as the navigation is performed and the referenced field is included in the results.
var customers = ctx.Customers.Include(c => c.State).Select(c => new { c.CustomerName, c.State.StateName }).ToList();
Below is the debugging output:
Further technical details
EF Core version: 1.0
Operating system: Windows 10
Visual Studio version: VS 2015
The text was updated successfully, but these errors were encountered: