Analyzes and optimizes Entity Framework Core queries in .NET code. Scans projects, detects N+1, missing AsNoTracking, cartesian explosion, and more, then rewrites slow queries.
Ships in TheCodeMan .NET AI ToolKit. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Find and fix the performance problems in Entity Framework Core queries, then return the optimized code with a short explanation of every change.
You don't need pasted snippets. Work directly from whatever target the user gives:
path/to/Query.cspath/to/Features/ (scan everything relevant under it).csproj / .sln or the repo rootgit clone --depth 1 <url> /tmp/repo && cd /tmp/repoDiscover the EF code yourself with Glob/Grep/Bash instead of asking for a paste. Locate candidates first, e.g.:
grep -rl "DbContext\|IQueryable" --include=*.cs <target> | grep -vi "/obj/\|/bin/"
grep -rn "\.Include(\|\.ToListAsync\|\.Where(\|\.Select(\|AsNoTracking" --include=*.cs <target>
On a large project, scan the matched files, prioritize the worst offenders, and don't read unrelated code. Always tell the user which files you scanned and group findings by file.
The user has shared EF Core code (queries, a DbContext, repositories, services) or a project/repo and wants it faster or reviewed. They may give a path, a folder, a solution, or a GitHub link — scan it yourself. Only ask for more if the target has no EF code or you need the entity/DbContext configuration to confirm a fix.
Apply every item. For each finding, state the problem, the impact, and the fix.
The classic killer. A loop (or lazy navigation access) that fires one query per row.
foreach over entities then .SomeNav; lazy loading enabled..Include() / .ThenInclude(), or project into a DTO that pulls everything in one query.AsNoTracking()Read-only queries should not pay the change-tracking cost.
.AsNoTracking() (or .AsNoTrackingWithIdentityResolution() when the same entity appears multiple times in the graph).Loading full entities when only a few columns are needed.
ToListAsync() of full entities, then only a couple of properties used..Select(x => new XDto { ... }) to fetch only needed columns. Projection also removes the need for Include and avoids tracking.Multiple collection Includes in one query multiply rows.
Included in the same query.AsSplitQuery(), or split into separate queries, or project. Note the trade-off (split query = multiple round-trips but no row multiplication).Work that silently runs in memory instead of SQL.
.AsEnumerable()/.ToList() before filtering/ordering..Skip().Take() on large offsets, or paging in memory.WHERE Id > @last ORDER BY Id) for deep pages; ensure OrderBy is present and indexed..Count() > 0, .ToList().Count, .Where(...).FirstOrDefault() != null..AnyAsync(predicate) for existence; .CountAsync(predicate) directly; avoid materializing.ToList(), First(), SaveChanges() in async code.ToListAsync(), FirstOrDefaultAsync(), SaveChangesAsync() with CancellationToken.ExecuteUpdateAsync() / ExecuteDeleteAsync() to do it in one SQL statement without loading entities.HasIndex), but mark "verify against your schema". Recommend logging the generated SQL (.LogTo(Console.WriteLine) or ToQueryString()) to confirm.## Summary
<one paragraph: what was slow and the headline fixes>
## Findings
1. [N+1] <file/line> — <problem> → <fix>
2. [No projection] ... → ...
## Optimized code
<the rewritten query/method, ready to paste>
## Verify on your side
- <index suggestions, SQL to inspect, anything needing the real schema/data>
For deeper patterns (compiled queries, DbContext pooling, split-query trade-offs, raw SQL escape hatches), see references/ef-core-patterns.md.
Include when the caller only reads data.ToQueryString().What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
entity-framework-core, ef-core, query-optimization, dotnet, n-plus-one
/dotnet-ai-toolkit:ef-core-query-optimizerfrom TheCodeMan .NET AI ToolKit
npx claudepluginhub stefanthecode/dotnet-ai-toolkit --plugin dotnet-ai-toolkit49 skills in this plugin
/adonet-data-access-auditorAudit and fix classic ADO.NET data-access code (SqlConnection / SqlCommand / SqlDataReader / DataSet) on .NET Framework. Use this skill whenever the user shares raw ADO.NET code, a DAL / repository built on SqlCommand, stored-proc calls, string-concatenated SQL, or mentions SQL injection, parameterized queries, connection leaks, "using / Dispose", reading the same column multiple times, transactions, or "why does my old data layer leak connections / is it safe". Always use this skill for classic ADO.NET review instead of answering from memory; it applies a fixed security + correctness + performance checklist and rewrites the code./async-await-auditorAudit C#/.NET code for async/await anti-patterns and concurrency bugs. Use this skill whenever the user shares async C# code or asks about deadlocks, async void, .Result/.Wait(), blocking calls, ConfigureAwait, sync-over-async, fire-and-forget tasks, CancellationToken usage, or "why does my async code hang/deadlock". Always use this skill for async correctness/performance reviews instead of answering from memory; it applies a fixed checklist and rewrites the code./authorization-policy-generatorDesign ASP.NET Core authorization — policy-based, role-based, and claims/requirement-based with custom authorization handlers and resource-based checks. Use this skill whenever the user wants authorization policies, role/claim checks, custom AuthorizationHandler, resource-based authorization, permission checks, or asks "how do I authorize this / policy vs role / restrict this endpoint to X". Always use this skill for authorization requests; it generates policies, handlers, and endpoint wiring.Other plugins' skills for the same job