Query: Optimize navigation property translation in projections
See original GitHub issueFor example, customers.Select(c => new { c.Id, Orders = c.Orders })
results in n+1 at the moment.
Make sure to consider the following scenarios when looking at this:
Issue Analytics
- State:
- Created 8 years ago
- Reactions:2
- Comments:16 (10 by maintainers)
Top Results From Across the Web
Query: Optimize navigation property translation in ...
The workaround would be to retrieve the scalar properties in one query and then pull back the children in a separate query. If...
Read more >How to: Use Projections to Create Custom Queries and ...
How to: Use Projections to Create Custom Queries and Optimize Performance ... Step 3 - Include Navigation Properties to the Items Loaded to...
Read more >Optimising Entity Framework Core Queries using Projection
Summary. We've seen that we can optimise the queries generated by Entity Framework by using a technique called projection, which allows Entity ...
Read more >Efficient Querying - EF Core
Project only properties you need. EF Core makes it very easy to query out entity instances, and then use those instances in code....
Read more >EF core 2.1 using take in projection
We have improved our query translation to avoid executing "N + 1" SQL queries in many common scenarios in which the usage of...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@MaklaCof I’m working on this feature right now. Its scheduled to be shipped with the next release of EF Core. Unless I encounter some unexpected issues the code should be in our dev branch in a next couple weeks or so - ready to be tested
@simeyla here is a sample of how a manually created query (using joins) would look like:
It’s quite tricky to write, but you can do filtering and custom projections on inner and outer collections. Basically the idea is to create a groupjoin, which pairs up the email entities and their tags - you can apply filter on emails directly (see:
where e.Id >3
, and filters to tags are applied on the grouping, seefrom t in grouping.Where(g => !g.Name.EndsWith("1")).DefaultIfEmpty()
When you apply all the filters, you project both into anonymous type. This will produce the following SQL, that fetches all the (filtered) emails and tags in one query:
now you need to group by the results by email, and shape the result into DTOs