Explicit loading for list of entries: context.Entries(...)...Load()
See original GitHub issueFor explicit loading EF Core offers (from docs):
var blog = context.Blogs
.Single(b => b.BlogId == 1);
context.Entry(blog)
.Reference(b => b.Owner)
.Load();
If I have, for expample, list of 10 entries, I need to 10 times call Reference(…).Load() in foreach
, that generate 10 SQL queries to DB.
How about optimized method Entries():
var blogs = context.Blogs
.Where(...)
.ToList();
context.Entries(blogs)
.Reference(b => b.Owner)
.Load();
which make a single SQL query like: select .... where [BlogOwner].[BlogId] in (?, ?, ?, ?, ?, ?)
Sorry, but I have not found similar functionality. Thanks
Issue Analytics
- State:
- Created 7 years ago
- Reactions:19
- Comments:10 (5 by maintainers)
Top Results From Across the Web
How to do explicit loading for multiple entries in EF?
1 Answer. Entry method give you the control over an entity attached to the current context, so before use it the entity must...
Read more >Explicit Loading Related Entities in EF 6 and EF Core
The Load() method executes the SQL query in the database to get the data and fill up the specified reference or collection property...
Read more >Explicit Loading of Related Data - EF Core
Explicit loading of related data with Entity Framework Core. ... You can explicitly load a navigation property via the DbContext.Entry(.
Read more >Explicit Loading in Entity Framework Core
Explicit Loading in EF Core is a technique we query and load the related entities with an explicit call. Explicit loading works very...
Read more >Entity Framework performance improvement: [Section 1]
Explicit loading is a technique in Entity Framework (EF) that allows you to load related entities on-demand, as opposed to automatically loading ...
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 Free
Top 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
Sometimes may need to eager/explicit load a relationship after the parent model has already been retrieved. For example, this may be useful if I need to dynamically decide whether to load related models:
This code works:
but code is not “dry”.
where statement
need to be hardcoded and match FK for Navigation-property. Context knows all about FK so it’s his “job” to load Navigation-properties properly.Sorry for my english (
To things you can try:
Include(b => b.Owner)