dotnet-entity-framework-core

Design, tune, and review EF Core data access with migrations, query translation, and performance patterns.

Updated Mar 31, 2026
One-click install
npx skills add https://github.com/zhenpengLai/myuseskill --skill dotnet-entity-framework-core-zhenpenglai
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: dotnet-entity-framework-core
Source: https://github.com/zhenpengLai/myuseskill/tree/main/dotnet-entity-framework-core
Command: npx skills add https://github.com/zhenpengLai/myuseskill --skill dotnet-entity-framework-core-zhenpenglai

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? EF Core code often ships with hidden performance problems like N+1 queries, client-side evaluation, missing indexes, and incorrect DbContext lifetimes. This Skill guides modeling, migrations, query optimization, and lifetime management so .NET data access behaves correctly under real workloads. ## Core Features & Use Cases - Query Optimization: Apply AsNoTracking, DTO projections, eager loading with split queries, compiled queries, and keyset pagination to eliminate N+1 problems and reduce roundtrips. - Migration & Schema Management: Create reviewable migrations, add indexes and data migrations, and generate idempotent SQL scripts for deployment. - Anti-Pattern Detection: Identify and fix common mistakes such as generic repository wrappers, lazy loading abuse, SaveChanges in loops, and monolithic DbContexts. - Use Case: When a code review reveals a slow endpoint loading orders, use this Skill to replace loop-based queries with a single Include plus AsSplitQuery, add a composite index, and verify the generated SQL. ## Quick Start Review my EF Core DbContext and order queries for N+1 problems and suggest optimized LINQ with proper indexes.

Frequently Asked Questions about dotnet-entity-framework-core

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 by using eager loading with Include() to fetch related data in one query, or project to DTOs with Select(). For large entity graphs, add AsSplitQuery() to avoid cartesian explosion from multiple joins.

How to improve EF Core query performance?▼

Use AsNoTracking() for read-only queries, project to DTOs instead of loading full entities, add indexes on filtered columns, and use compiled queries for hot paths. EF Core 7+ also supports ExecuteUpdateAsync and ExecuteDeleteAsync for bulk operations without loading entities.

Should I use a generic repository pattern with EF Core?▼

Generic repositories over DbContext are an anti-pattern because they hide query composition and force client-side evaluation. Use DbContext directly, or create specific repository methods with meaningful queries like GetExpensiveProductsAsync.

What DbContext lifetime should I use in ASP.NET Core?▼

Use scoped lifetime, which is the default for AddDbContext, aligning the context with the request unit of work. Avoid singleton or static contexts, which cause memory growth and stale data; for background services, create an explicit scope per operation.

Does EF Core support batch updates without loading entities?▼

Yes, EF Core 7 and later support ExecuteUpdateAsync and ExecuteDeleteAsync, which run set-based SQL directly against the database. This avoids loading entities into memory and issuing one statement per row.

Why is my EF Core LINQ query loading all rows into memory?▼

This happens when a LINQ expression cannot be translated to SQL, forcing client-side evaluation. Enable logging or call ToQueryString() to inspect generated SQL, and replace untranslatable method calls with translatable constructs like EF.Functions.Like.