optimizing-ef-core-queries

Diagnose and optimize slow Entity Framework Core queries by fixing N+1 patterns and tracking overhead.

Updated Aug 9, 2026
One-click install
npx skills add https://github.com/adinj00/player-performance --skill optimizing-ef-core-queries-adinj00
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: optimizing-ef-core-queries
Source: https://github.com/adinj00/player-performance/tree/main/.agents/skills/optimizing-ef-core-queries
Command: npx skills add https://github.com/adinj00/player-performance --skill optimizing-ef-core-queries-adinj00

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? EF Core applications often suffer from slow queries, excessive SQL statements, and high database load caused by N+1 patterns, unnecessary change tracking, and client-side evaluation. This Skill provides a systematic workflow to identify and fix these performance issues. ## Core Features & Use Cases - N+1 Detection and Fixes: Enable query logging, then resolve N+1 patterns using Include, AsSplitQuery, or projection-based queries. - Tracking and Compilation Optimization: Apply AsNoTracking for read-only queries and EF.CompileAsyncQuery for hot paths. - Use Case: Your API endpoint loads orders and then loops through items, generating hundreds of SQL statements. Use this Skill to rewrite it with eager loading and projection, reducing it to one or two queries. ## Quick Start Analyze my EF Core query that fetches orders with their items and optimize it to eliminate the N+1 problem.

Frequently Asked Questions about optimizing-ef-core-queries

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix N+1 queries in Entity Framework Core?

Fix N+1 queries in EF Core by eager loading related data with Include, using AsSplitQuery for multiple collections to avoid cartesian explosion, or projecting only needed columns with Select. Enable query logging first to confirm the N+1 pattern.

When should I use AsNoTracking in EF Core?

Use AsNoTracking for read-only queries where entities will not be updated, since change tracking adds significant overhead. Use AsNoTrackingWithIdentityResolution when queries return duplicate entities to avoid duplicated objects in memory.

Should I use single query or split query with Include in EF Core?

Use a single query for one level of Include or when transaction consistency matters. Use AsSplitQuery when including multiple collections or large child collections, since a single JOIN can cause cartesian explosion and transfer redundant data.

Does this apply to Dapper or raw ADO.NET performance issues?

No, this workflow targets EF Core specifically. It also does not cover database-side problems like missing indexes or bad schema design, which require database tuning rather than ORM query changes.

Why does my EF Core query load the entire table into memory?

This happens when ToList is called before Where, causing client-side evaluation. Always filter with Where before materializing results, use Any instead of Count for existence checks, and use EF.Functions.Like instead of string.Contains for SQL translation.