Junior
From PDF
EF Core
Entity Framework Core
What is the N+1 query problem? How can lazy loading lead to it?
The N+1 problem occurs when:
- 1 query loads N parent entities
- N additional queries load related entities (1 per parent)
Example (lazy loading):
foreach (var blog in context.Blogs)
{
Console.WriteLine(blog.Owner.Name); // triggers a query for each
blog
}
This causes N+1 queries, which can hurt performance significantly.
✅ Solution: Use eager loading with .Include() to fetch everything in one query.
Share this Q&A
Share preview image: https://www.toolliyo.com/images/toolliyo-logo.png