optimizing-ef-core-queries

Installation
SKILL.md

Optimizing EF Core Queries

Diagnose and fix slow Entity Framework Core (EF Core) queries. Start from the generated SQL/logs, apply the smallest change that removes the bottleneck, and confirm the fix by re-reading the SQL and the query count. Prefer changes that reduce round-trips, duplicated rows, scans, or per-call translation cost over micro-optimizations. Apply one change at a time and re-measure.

When to Use

  • EF Core queries are slow or emit far more SQL statements than expected
  • The same query repeats once per row (N+1 / lazy loading)
  • Multiple collection Includes blow up or duplicate rows
  • Deep pages slow down as Skip grows, or bulk updates load rows just to modify them
  • A filtered/sorted query scans even though the column is indexed, or a filtered/sorted column has no supporting index
  • A hot, frequently-executed query pays EF Core's LINQ-translation cost on every call

When Not to Use

  • The code uses Dapper or raw ADO.NET, not EF Core. Answer the SQL/indexing/query-plan question directly; do not introduce a DbContext or recommend AsNoTracking, Include, AsSplitQuery, or other EF Core APIs.

First: capture the generated SQL

Installs
1.6K
Repository
dotnet/skills
GitHub Stars
5.1K
First Seen
Mar 10, 2026
optimizing-ef-core-queries — dotnet/skills