Eager vs Explicit Loading
What are the key trade-offs of Eager vs Explicit Loading? When would you choose it vs alternatives?
Answers use simple, clear English.
Quick interview answer
Pros: Include gives predictable SQL; projection Select reduces over-fetching. Cons: Cartesian explosion with multiple Includes — use split queries.
Detailed answer
Pros: Include gives predictable SQL; projection Select reduces over-fetching. Cons: Cartesian explosion with multiple Includes — use split queries. Decision: pick when benefits outweigh operational cost. Core: Include/ThenInclude eager-loads related data in one query. Explicit loading: reference/load after query. Avoid lazy loading in web apps (N+1 in loops). Real-time example: Order list with items: .Include(o => o.Items) prevents N+1 when rendering line counts. Pros: Include gives predictable SQL; projection Select reduces over-fetching. Cons: Cartesian explosion with multiple Includes — use split queries. Common mistakes: Lazy loading enabled globally causing hidden N+1 in foreach. Best practices: Prefer Select projection DTOs; AsSplitQuery for multiple collections. Audience level: Engineering Manager.
Full explanation
Include/ThenInclude eager-loads related data in one query. Explicit loading: reference/load after query. Avoid lazy loading in web apps (N+1 in loops).
Real example & use case
Order list with items: .Include(o => o.Items) prevents N+1 when rendering line counts.
Pros & cons
Pros: Include gives predictable SQL; projection Select reduces over-fetching. Cons: Cartesian explosion with multiple Includes — use split queries.
Common mistakes
Lazy loading enabled globally causing hidden N+1 in foreach.
Best practices
Prefer Select projection DTOs; AsSplitQuery for multiple collections.
Follow-up questions
Open one as its own read / solve / listen card