DEV Community

chandana pushpakumara
chandana pushpakumara

Posted on

EF Core 10 Performance Issue

The most common performance issue is fetching a list of items and then calling the database again for each child record.

The “Slow” Method(N+1):

var blogs = await context.Blogs.ToListAsync(); 
foreach (var blog in blogs)
{
    var posts = await context.Posts.Where(p => p.BlogId == blog.Id).ToListAsync();
}
Enter fullscreen mode Exit fullscreen mode

The EF Core 10 “Fast” Method(Filtered Include):

var blogs = await context.Blogs
    .Include(b => b.Posts.Where(p => p.IsPublished)) // Filtered Include
    .ToListAsync();
Enter fullscreen mode Exit fullscreen mode

EF Core 10 Performance Result

Here I used 100000 records. My benchmark result shows that the N+1 query problem was over 280x slower than using Include(). However, optimizations like projection AsNoTracking() showed minimal gains in small datasets, highlighting that performance tuning depends heavily on scale.

I wrote a detailed article about 4 other optimization traps here: EF Core 10 Performance: Fixing 5 Common Slow Queries.

Top comments (0)