---
title: "How do I avoid the N+1 query problem in EF Core?"  
description: "How do I avoid the N+1 query problem in EF Core?"  
author: "Katherine Sullivan"  
published: 2026-11-13  
updated: 2026-11-13  
canonical: https://www.mindstick.com/forum/163005/how-do-i-avoid-the-n-1-query-problem-in-ef-core  
category: "C# and .NET"  
tags: ["Entity Framework Core", "N+1 problem", "Include", "performance", "linq"]  
reading_time: 1 minute  

---

# How do I avoid the N+1 query problem in EF Core?

My page loads 200 orders and the logs show hundreds of small SQL queries. What is going on and how do I fix it?

## Replies

### Reply by Laura Michiels

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.


---

Original Source: https://www.mindstick.com/forum/163005/how-do-i-avoid-the-n-1-query-problem-in-ef-core

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
