optimizing-ef-core-queries

Identify and fix EF Core query performance issues with N+1 resolution and tracking modes.

Updated Mar 18, 2026
One-click install
npx skills add https://github.com/Mozart-Alkhateeb/ai_sdlc_todo --skill optimizing-ef-core-queries-mozart-alkhateeb
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: optimizing-ef-core-queries
Source: https://github.com/Mozart-Alkhateeb/ai_sdlc_todo/tree/main/.agents/skills/optimizing-ef-core-queries
Command: npx skills add https://github.com/Mozart-Alkhateeb/ai_sdlc_todo --skill optimizing-ef-core-queries-mozart-alkhateeb

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Optimize EF Core queries by fixing N+1 problems, choosing correct tracking modes, using compiled queries, and avoiding common performance traps. Use when EF Core queries are slow, generating excessive SQL, or causing high database load.

Core Features & Use Cases

  • N+1 pattern detection and resolution
  • No-tracking vs tracking mode tuning for read-heavy workloads
  • Compiled queries and projection strategies for hot paths
  • Guidance for includes, split queries, and common EF Core traps

Quick Start

Run a profiling pass on a failing EF Core query and implement the recommended optimizations in the codebase.

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 EF Core N+1 query problems?

To fix EF Core N+1 query problems, you need to detect missing includes and apply proper projection strategies. This ensures related data is loaded in a single database round-trip rather than executing separate queries for each entity.

What is the difference between tracking and no-tracking modes in EF Core?

Tracking modes in EF Core monitor entity state changes for saving, while no-tracking modes skip this overhead for read-heavy workloads. Choosing no-tracking for read-only queries significantly reduces database load and improves query performance.

When should I use compiled queries in EF Core?

You should use compiled queries in EF Core for hot paths where queries execute repeatedly. They optimize performance by caching the query translation, avoiding the overhead of parsing and compiling the same query structure on every execution.

How do I optimize EF Core queries causing high database load?

To optimize EF Core queries causing high database load, you must run a profiling pass to identify excessive SQL generation. Applying correct tracking settings, split queries, and compiled queries mitigates these performance traps.

What are common EF Core performance traps with includes and split queries?

Common EF Core performance traps with includes include generating massive Cartesian explosions. Using split queries loads related collections in separate SQL queries, reducing memory overhead and avoiding excessive SQL generation for complex graphs.