Batched queries for explicit loading
- Dominant language
- C#
- Stars
- 14.8k
- Forks
- 3.4k
- PR merge metrics
- PR metrics pending
Description
Includes and Lazy Loading are in my eyes the two major ways to query for related data. Both of them have their disadvantages: Includes make it hard to optimize queries when reusing them, and lazy loading can cause a massive amount of DB round trips. I'm proposing a middle ground to this.
Tracking which query an entity originated from (possibly by creating a new proxy on each query, even if the object is already cached locally - maybe EF already does this?) and, when a navigation is lazy-loaded, load that same navigation for all entities of that type from the query it originated from, effectively like a lazily-loaded split-query include.
I see some possible problems with this, like I mentioned above, I haven't looked at the current code and don't know if EF Core already creates a new proxy for each query even if the entity is already in memory. Tracking the original query would probably have to be done through the proxy object too. Also, making sure that you only run the query once even if accessed multiple times simultaneously could be difficult?
Contributor guide
Assessment
This issue has not been assessed yet.