efcore-patterns

Optimize EF Core queries, migrations, and change tracking in .NET applications.

Updated Apr 23, 2026
One-click install
npx skills add https://github.com/MudraMartin/dotlight-skillset --skill efcore-patterns-mudramartin
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: efcore-patterns
Source: https://github.com/MudraMartin/dotlight-skillset/tree/main/dotnet/efcore-patterns
Command: npx skills add https://github.com/MudraMartin/dotlight-skillset --skill efcore-patterns-mudramartin

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve?

This Skill unit helps .NET developers optimize their Entity Framework Core (EF Core) database operations, addressing common issues with query performance, migration management, and change tracking.

Core Features & Use Cases

  • NoTracking by Default: Enhance performance by disabling change tracking for most queries.
  • Migration Management: Leverage EF Core CLI commands to manage database migrations efficiently.
  • Dedicated Migration Service: Ensure migrations are executed separately from the main application, improving separation of concerns.
  • ExecutionStrategy for Retries: Handle transient database failures gracefully.
  • Explicit Updates: Properly manage entities for update when NoTracking is used.
  • Bulk Operations: Execute efficient bulk updates and deletes to improve performance.
  • Prevent N+1 Queries: Avoid performance issues with eager loading.
  • DbContext Lifetime: Manage DbContext lifecycle for different scenarios, such as scoped by default in ASP.NET Core or using a factory pattern for long-lived objects.

Quick Start

Use the efcore-patterns skill to configure your DbContext for NoTracking and manage database migrations with the EF Core CLI.

Frequently Asked Questions about efcore-patterns

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

FAQPage Schema
How do I optimize Entity Framework Core query performance for read-heavy operations?

Optimize EF Core query performance by disabling change tracking with NoTracking by default. This prevents the DbContext from tracking entity state, significantly reducing memory overhead and improving read speed for queries.

What's the best way to handle transient database failures in EF Core?

Handle transient database failures in EF Core by implementing an ExecutionStrategy. This mechanism automatically retries failed operations, ensuring graceful recovery from temporary connection drops or timeouts.

How do I prevent N+1 query issues when loading related data in EF Core?

Prevent N+1 query issues in EF Core by using eager loading. Fetching related data in a single query avoids repeated database round trips, drastically improving application responsiveness.

How do I manage database migrations separately from the main application in EF Core?

Manage EF Core migrations separately by using a dedicated migration service and EF Core CLI commands. This approach ensures migrations are executed independently, improving separation of concerns.

How should I manage DbContext lifetime for long-lived objects in .NET?

Manage DbContext lifetime for long-lived objects by using a factory pattern instead of the default scoped lifetime. This ensures clean context instances, preventing tracking bloat in background services.

How do I perform bulk updates and deletes efficiently with Entity Framework Core?

Execute efficient bulk updates and deletes in EF Core to process large datasets in batches. This approach bypasses individual entity tracking, minimizing memory usage and improving performance.