This is the N+1 problem: one query loads the orders, then a separate query runs for each order when you touch a related property such as order.Customer or order.Items. It is common with lazy loading or with loops over navigation properties.
Ways to fix it:
Include: context.Orders.Include(o => o.Customer) loads the related rows in the same query.
Projection: select only what the page needs, for example Select(o => new OrderDto { Id = o.Id, CustomerName = o.Customer.Name }). This is often the best fix because it also reduces the columns fetched.
AsSplitQuery(): if Include on several collections creates a huge join, split it into a few queries.
To catch it, turn on EF Core logging (LogTo or the console) in development and count the queries per page. If you see the same query repeated with different ids, you have N+1.
Markdown for AI
A clean, structured version of this page for AI assistants and LLMs.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
This is the N+1 problem: one query loads the orders, then a separate query runs for each order when you touch a related property such as order.Customer or order.Items. It is common with lazy loading or with loops over navigation properties.
Ways to fix it:
context.Orders.Include(o => o.Customer)loads the related rows in the same query.Select(o => new OrderDto { Id = o.Id, CustomerName = o.Customer.Name }). This is often the best fix because it also reduces the columns fetched.To catch it, turn on EF Core logging (LogTo or the console) in development and count the queries per page. If you see the same query repeated with different ids, you have N+1.