Entity Framework Core Interview Question #40
What is explicit loading in EF Core?
Relationships, Navigation Properties & Loading Data Junior Beginner
Quick Interview Answer
Explicit loading loads related data for an entity after that entity has already been queried and is being tracked.
Detailed Explanation
Explicit loading loads related data for an entity after that entity has already been queried and is being tracked.
The Entry API can load a reference or collection navigation when the application decides that the data is needed.
Explicit loading provides control, but repeated loading inside loops can cause many database round trips and create an N+1 query problem.
Code Example
var customer = await db.Customers.FindAsync(id);
await db.Entry(customer!)
.Collection(c => c.Orders)
.LoadAsync();