What is explicit loading? When & how to use it?
Short answer: Explicit loading means loading related data manually, after the main entity is loaded.
Explain a bit more
Use when: You need full control over what and when to load You don’t want automatic lazy loading var blog = context.Blogs.First(); context.Entry(blog) .Collection(b => b.Posts) .Load(); context.Entry(blog) .Reference(b => b.Owner) .Load(); ✅ Use .Reference().Load() for single navigation ✅ Use .Collection().Load() for collections Explicit loading means loading related data manually, after the main entity is loaded. Explicit loading means loading related data manually, after the main entity is loaded. Use when: You need full control over what and when to load You don’t want automatic lazy loading
Example code
var blog = context.Blogs.First(); context.Entry(blog) .Collection(b => b.Posts) .Load(); context.Entry(blog) .Reference(b => b.Owner) .Load(); ✅ Use .Reference().Load() for single navigation ✅ Use .Collection().Load() for collections Explicit loading means loading related data manually, after the main entity is loaded. Explicit loading means loading related data manually, after the main entity is loaded. Use when: You need full control over what and when to load You don’t want automatic lazy loading Example: var blog = context.Blogs.First(); context.Entry(blog) .Collection(b => b.Posts) .Load(); context.Entry(blog) .Reference(b => b.Owner) .Load(); ✅ Use .Reference().Load() for single navigation ✅ Use .Collection().Load() for collections Explicit loading means loading related data manually, after the main entity is loaded. Use when: You need full control over what and when to load You don’t want automatic lazy loading Example: var blog = context.Blogs.First(); context.Entry(blog) .Collection(b => b.Posts) .Load(); context.Entry(blog) .Reference(b => b.Owner) .Load(); ✅ Use .Reference().Load() for single navigation ✅ Use .Collection().Load() for collections
Real-world example (ShopNest)
ShopNest’s order service uses EF Core to save an Order and its line items in one SaveChangesAsync() call inside a transaction.
Say this in the interview
- Define — one clear sentence (the short answer above).
- Example — relate it to a project like ShopNest or your real work.
- Trade-off — when you would not use it.
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png