Tutorials Entity Framework Core Tutorial

Explicit Loading in EF Core

Explicit 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 47 of 100

Explicit Loading in EF Core

Beginner ✓Intermediate ✓AdvancedProfessional

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

What is this?

Explicit loading fetches related data on demand with Entry(entity).Reference().LoadAsync() or Collection().LoadAsync() after the principal is already loaded.

Why should you care?

ShopNest order detail API loads Order first, then explicitly loads Items only if user expands line items — saves bandwidth on summary view.

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 order = await _context.Orders
    .AsNoTracking()
    .FirstOrDefaultAsync(o => o.Id == orderId);

if (order is null) return NotFound();

await _context.Entry(order).Collection(o => o.Items).LoadAsync();
await _context.Entry(order).Reference(o => o.Customer).LoadAsync();

What happened?

  • First query loads Order only.
  • LoadAsync on Collection and Reference issues separate SELECTs for Items and Customer when you choose.

Practice next

  1. Load principal with AsNoTracking if read-only.
  2. Attach entity if detached before Entry().LoadAsync.
  3. Use Query() on collection for filtered explicit load.
  4. Use Entry(order).Collection(o => o.Items).Query().Where(i => i.Quantity > 1).LoadAsync().
  5. Load reference only when query param ?includeCustomer=true.

Remember

Explicit load uses Entry().LoadAsync. Good for conditional related data. Entity must be tracked or attached.

ShopNest order expand

Mobile order list loads headers; detail screen explicitly loads Items collection.

Outcome: List view stays fast; detail view pays cost only when opened.

Interview prep for this lesson

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

Junior PDF Detailed
What is explicit loading? When & how to use it?
Short answer: Explicit loading means loading related data manually, after the main entity is loaded. Explain a bit more Use when: You need full control over what and when to load You don’t want automatic lazy loading var…
Junior PDF Detailed
What is explicit loading?
Short answer: When & how to use it? Explicit loading means loading related data manually, after the main entity is loaded. Use when: You need full control over what and when to load You don’t want automatic lazy load…
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…
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…
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