# Optimizing Ef Core Queries

Review and optimize application data access that uses Entity Framework Core (EF Core).

- Repository: https://github.com/dotnet/skills (5787 stars)
- Category: Data and ML
- License: MIT
- Last updated: 2026-11-01
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add dotnet/skills --skill optimizing-ef-core-queries -g -a claude-code -y`
Codex: `npx skills add dotnet/skills --skill optimizing-ef-core-queries -g -a codex -y`
Cursor: `npx skills add dotnet/skills --skill optimizing-ef-core-queries -g -a cursor -y`
Gemini CLI: `npx skills add dotnet/skills --skill optimizing-ef-core-queries -g -a gemini-cli -y`
Claude Code plugin marketplace: `/plugin marketplace add dotnet/skills`

## Description

Review and optimize application data access that uses Entity Framework Core (EF Core). Use for EF Core performance and correctness reviews of services, repositories, imports, and background jobs: slow or memory-heavy queries, excessive round-trips, hidden SaveChanges, premature materialization, dynamic query construction, result-graph tracking, bulk writes, DbContext lifetime or overlapping operations, search semantics, paging, raw SQL, and model/index coverage. Use whether or not EF Core owns the schema. For EF Core, not Dapper or raw ADO.NET.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# Optimizing EF Core Queries

Diagnose and fix slow or incorrect application data access built on EF Core. In a source-only review, trace the code without executing it and separate proven code behavior from runtime assumptions. When SQL, logs, or plans are available, use them to confirm the bottleneck. Prefer changes that reduce round-trips, duplicated rows, scans, or per-call translation cost over micro-optimizations.

## 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 `Include`s 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.

## Source review workflow

The rest: https://github.com/dotnet/skills/blob/HEAD/plugins/dotnet-data/skills/optimizing-ef-core-queries/SKILL.md
