Tutorials Entity Framework Core Tutorial

Eager Loading in EF Core

Eager Loading in EF Core: free step-by-step lesson with examples, common mistakes, and interview tips — part of Entity Framework Core Tutorial on Toolliyo Academy.

On this page

Entity Framework Core Tutorial · Lesson 45 of 100

Eager Loading in EF Core

Beginner ✓Intermediate ✓AdvancedProfessional

Advanced · 3 — Production skills · ~6 min · Module 5: Relationships

What is this?

Eager loading fetches related entities upfront using Include and ThenInclude on the initial query — EF generates JOINs or multiple queries with split option.

Why should you care?

ShopNest product detail page needs Category and Tags immediately — one shaped query beats lazy loading surprises.

See it live — copy this example

Paste into a .NET project with EF Core packages, then run with LocalDB/SQL Server (dotnet ef / dotnet run).

var product = await _context.Products
    .Include(p => p.Category)
    .Include(p => p.Tags)
    .Include(p => p.Detail)
    .AsSplitQuery()
    .FirstOrDefaultAsync(p => p.Id == id);

What happened?

  • Each Include adds related data to the same query (or split queries).
  • AsSplitQuery avoids cartesian explosion from multiple collections.

Practice next

  1. List required navigations for the UI screen.
  2. Add Include/ThenInclude before FirstOrDefaultAsync.
  3. Enable split query when including multiple collections.
  4. Swap AsSplitQuery off and compare row multiplication in SQL profiler.
  5. Use filtered include: Include(p => p.Reviews.Where(r => r.IsApproved)).

Remember

Include loads related data eagerly. ThenInclude walks deeper graphs. Split query helps multiple collection Includes.

ShopNest PDP load

Product detail endpoint Includes Category, Tags, Detail in one split query.

Outcome: Page renders without N+1 lazy load latency spikes.

Interview prep for this lesson

Practice these questions aloud after reading—each links to a full structured answer.

Junior PDF Detailed
What is eager loading?
Short answer: Eager loading loads related data as part of the initial query, reducing round-trips to the database. ✅ Use .Include() to load related entities: var blogs = context.Blogs .Include(b => b.Posts) .ToList();…
Junior PDF Detailed
What is eager loading?
Short answer: How is .Include() / .ThenInclude() used? Eager loading loads related data as part of the initial query, reducing round-trips to the database. ✅ Use .Include() to load related entities: var blogs = context.B…
Mid PDF Detailed
What performance implications are there for eager vs lazy loading?
Short answer: Loading Type Pros Cons Eager Fewer queries, good for large data sets Loads everything even if not used Lazy Loads only when needed Risk of N+1 queries, more round-trips Explicit Fine-grained control More co…
Junior PDF Detailed
What is lazy loading?
Short answer: re proxies? Lazy loading delays the loading of related data until it's accessed for the first time. EF Core requires proxies for lazy loading: Install NuGet: Microsoft.EntityFrameworkCore.Proxies Enable in…
Junior PDF Detailed
What is lazy loading?
Short answer: How to enable lazy loading in EF Core? What are proxies? Lazy loading delays the loading of related data until it's accessed for the first time. EF Core requires proxies for lazy loading: Install NuGet: Mic…
Questions on this lesson 0

Sign in to ask a question or upvote helpful answers.

No questions yet — be the first to ask!

Entity Framework Core Tutorial
Course syllabus

Entity Framework Core Tutorial

Module 1: EF Core Fundamentals
Module 2: Code First Approach
Module 3: CRUD Operations
Module 4: LINQ
Module 5: Relationships
Module 6: Advanced EF Core
Module 7: Performance Optimization
Module 8: Enterprise Architecture
Module 9: Testing & Debugging
Module 10: Real-World Projects
Toolliyo Assistant
Ask about tutorials, ebooks, training, pricing, mentor services, and support. I use public site content only—not admin or internal tools.

care@toolliyo.com

Need callback? Share your details