0Pricing
C# Academy · Lesson

Eager, Lazy & Explicit Loading

Control when related data is loaded using Include, ThenInclude, lazy loading proxies, and explicit Load calls.

Three Loading Strategies

EF Core offers three strategies for loading related data: Eager Loading (load together with query), Lazy Loading (load on access), and Explicit Loading (load on demand). Choosing the right one avoids the N+1 problem and unnecessary database roundtrips.

Eager Loading with Include

Eager loading uses Include() to JOIN related data in the same SQL query. This is the most predictable strategy and avoids N+1 issues.

// Single query with JOIN
var blogs = await _db.Blogs
    .Include(b => b.Posts)
    .Where(b => b.IsActive)
    .ToListAsync();

// SQL: SELECT * FROM Blogs LEFT JOIN Posts ON ...

All lessons in this course

  1. Eager, Lazy & Explicit Loading
  2. Raw SQL, Stored Procedures & Interpolation
  3. Compiled Queries & Performance
  4. Global Query Filters & Owned Entities
← Back to C# Academy