Roadmap › Entity Framework (EF6 & EF Core) › Module: Performance and Advanced
Lessons in this course (15)

13. EF Core performance checklist

Advanced★ Must knowLesson 13 of 15
  1. Project with Select — fetch only needed columns.
  2. AsNoTracking for read-only queries.
  3. Avoid N+1 — no lazy loading in loops; Include or projection.
  4. AsSplitQuery for multiple collection includes (cartesian explosion).
  5. Paginate; never load whole tables.
  6. Indexes for filters/joins/order-bys (HasIndex).
  7. ExecuteUpdate/ExecuteDelete for set-based changes.
  8. AddDbContextPool and compiled queries (EF.CompileAsyncQuery) for hot paths.
  9. Keep contexts short-lived; don't track thousands of entities (DetectChanges cost).
  10. Check generated SQL (ToQueryString, logging) and execution plans; drop to Dapper/raw SQL for complex reports.
  11. Avoid client-side ToList() before Where.
  12. Use AnyAsync for existence, CountAsync only when needed.
csharp
private static readonly Func<AppDbContext, int, Task<Product?>> GetById =
    EF.CompileAsyncQuery((AppDbContext db, int id) => db.Products.FirstOrDefault(p => p.Id == id));