Skip to main content

How do you implement eager, lazy, and explicit loading?

Mid ASP.NET Web API
Quick Answer Eager loading: Include() loads related entities in one query (JOIN). Good when you always need the related data. Lazy loading: related entities load when first accessed (requires proxy). Risk of N+1 queries - avoid in Web API. Explicit loading: context.Entry(entity).Collection(x => x.Orders).LoadAsync() - load on demand. Choose eager for predictable queries, explicit for conditional loading, avoid lazy in APIs.

Answer

Eager: Include()

Lazy: Navigation property auto-loading (requires proxies)

Explicit: context.Entry(entity).Collection(...).Load()

S
SugharaIQ Editorial Team Verified Answer

This answer has been peer-reviewed by industry experts holding senior engineering roles to ensure technical accuracy and relevance for modern interview standards.

Want to bookmark, take notes, or join discussions?

Sign in to access all features and personalize your learning experience.

Sign In Create Account

Source: SugharaIQ

Ready to level up? Start Practice