-
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: Selecting scalar properties alongwith entity fails to lift and causes N+1 eval #11186
Comments
The difference is As a work-around you can construct object Parent manually by selecting individual properties and avoid materialization code path. |
It looks like just a technical imperfections at first, but I think it should be fixed with a high priority, because these queries are commonly used here and there.
|
@smitpatel Seems like the title should be improved. |
Can this be added to the 2.1 milestone? |
Clearing up the milestone to discuss taking these scenarios into account in the query design for 3.0. We are already overbooked for 3.0 so we may not be able to adress it, however I would like if possible that the design doesn't prevent us from being able to lift in this case. |
I had similar issue with following query (MIN was unexpectedly submited to SQL server as separate query):
and as a workaround I wrote it this way:
After translation to SQL, it generated for that InceptionDate column nice subquery in select clause with MIN statement, just like one would do when writing SQL directly.. |
I just ran into this problem, and read that in EF Core 3.0 this might get addressed but seems hard. This generates N + 1 queries from item in Items
select new
{
Owned = OwnedItems.Any(own => own.UserId == userId && own.ItemId == item.Id),
Item = item
} This one generates only 1 query from item in Items
select new
{
Owned = OwnedItems.Any(own => own.UserId == userId && own.ItemId == item.Id),
Item = new Item { Id = item.Id, Name = item.Name, ... Every single property listed one by one... }
} I understand that the first version needs to use the 'materialization code path' so it's different, but i can manually materialize the item by typing a lot. Some helpful people lead me here from |
Not sure if I have the same issue or if I'm doing something wrong, see code example below, might be isolated to the Max operator;
This is generating multiple queries to get the Max(child.DateOfBirth) |
Another example from me. Query definition:
Issue ExplanationMain query generated:
So Entity Framework understands the Expected:EF Core could have joined UserPhotos and UserLikes by understanding the relation is a
PostPhotos is a Further technical detailsEF Core: 3.0.0-preview3.19153.1 But I do want to emphasize that the join functionality actually works, what's missing is understanding a join in the query is one to zero or one at runtime. If it is defined in the entity the results are expected. So I can actually provide the Primary User Photo Id in the entity and refer to the Photo table as one to one for that property, that should work, but that would mean changing the database design to make EF work which would result in redundant data that needs to be kept updated. |
This has been done. |
//With classic Parent-Children (like in issue #10472)
This works well (within single select):
But this works as 2N+1 queries:
That's a bug? Or what's the problem, I cannot see any difference...
That's in 2.1.0-preview1
The text was updated successfully, but these errors were encountered: