Entity Framework Core Interview Question #41
What is lazy loading in EF Core?
Relationships, Navigation Properties & Loading Data Junior Beginner
Quick Interview Answer
Lazy loading retrieves related data automatically when a navigation property is accessed. EF Core can support lazy loading through proxies or other configured mechanisms.
Detailed Explanation
Lazy loading retrieves related data automatically when a navigation property is accessed. EF Core can support lazy loading through proxies or other configured mechanisms.
It can make code convenient, but database queries become less visible. Accessing navigation properties in a loop can unexpectedly issue many SQL queries.
For web applications, many teams prefer explicit query shapes using Include or projection because database access is easier to reason about and optimize.
Code Example
// When lazy-loading proxies are intentionally used:
builder.Services.AddDbContext<AppDbContext>(options =>
options.UseLazyLoadingProxies()
.UseSqlServer(connectionString));
// Navigation properties generally need to be virtual
// for proxy-based lazy loading.