ef-queries

Optimize EF Core queries with AsNoTracking, projections, and split queries.

4|1|Updated Mar 15, 2026
One-click install
npx skills add https://github.com/FaysilAlshareef/dotnet-ai-kit --skill ef-queries
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ef-queries
Source: https://github.com/FaysilAlshareef/dotnet-ai-kit/tree/main/skills/data/ef-queries
Command: npx skills add https://github.com/FaysilAlshareef/dotnet-ai-kit --skill ef-queries

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Many EF Core queries accidentally load too much data, perform extra database round-trips, or create N+1 performance problems; this Skill focuses on patterns that make queries efficient, safe, and scalable for .NET applications.

Core Features & Use Cases

  • Read-only performance: Apply AsNoTracking and projection to return only the columns needed for UI or APIs.
  • N+1 prevention: Use split queries or appropriate includes to avoid cartesian explosion when loading related collections.
  • Hot-path optimization: Compile frequently used queries for reuse and high throughput, and use pagination and batch operations to control result size.
  • Raw SQL & bulk work: Employ parameterized raw SQL and ExecuteUpdateAsync/ExecuteDeleteAsync for complex aggregations or bulk changes.
  • Use Case: Replace full entity loads in list endpoints with Select projections and paginated responses, compile detail lookups for hot endpoints, and convert load-and-update loops to ExecuteUpdateAsync for archival jobs.

Quick Start

Optimize this query to use AsNoTracking, project results to a DTO with Select, apply pagination, and add AsSplitQuery where multiple Includes cause N+1 issues.

Frequently Asked Questions about ef-queries

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

FAQPage Schema
How do I fix N+1 query problems in EF Core?

Fix EF Core N+1 query problems by using AsSplitQuery to load related collections separately, preventing cartesian explosion and avoiding extra database round-trips when applying multiple Includes.

What is the best way to optimize Entity Framework Core LINQ queries for read-only APIs?

Optimize Entity Framework Core LINQ queries for read-only APIs by applying AsNoTracking to disable change tracking and using Select to project results directly to DTOs, returning only needed columns.

When should I use compiled queries in EF Core?

Use compiled queries in EF Core for hot paths and frequently executed detail lookups to compile LINQ once for reuse, ensuring high throughput and reducing query translation overhead.

How do I perform bulk updates without loading entities in EF Core?

Perform bulk updates in EF Core without loading entities by using ExecuteUpdateAsync and ExecuteDeleteAsync for bulk changes, converting load-and-update loops into direct database operations for archival jobs.

Does EF Core support parameterized raw SQL for complex aggregations?

Yes, EF Core supports parameterized raw SQL to execute complex aggregations safely, allowing you to bypass LINQ limitations while protecting against SQL injection in .NET applications.