data-efcore-patterns

Configure EF Core data access patterns for NoTracking defaults and CLI migrations.

3|Updated Jan 24, 2024
One-click install
npx skills add https://github.com/akoken/dotfiles --skill data-efcore-patterns
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: data-efcore-patterns
Source: https://github.com/akoken/dotfiles/tree/main/config/.copilot/skills/data-efcore-patterns
Command: npx skills add https://github.com/akoken/dotfiles --skill data-efcore-patterns

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

EF Core can be complex to configure for performance and migrations. This skill presents practical patterns to ensure efficient data access, reliable migrations, and safer update semantics in real-world apps.

Core Features & Use Cases

  • NoTracking by default to boost read performance, with explicit tracking when needed.
  • Never edit migrations manually to maintain a clean history and reliable deployments.
  • Dedicated Migration Service pattern (Aspire) to run migrations before app startup and isolate seeding in tests.
  • Use execution strategies to gracefully retry transient failures and preserve data integrity.
  • Safe bulk operations with ExecuteUpdate/ExecuteDelete to run single SQL statements instead of loading entities.
  • Proper DbContext lifetime management in DI for ASP.NET Core, background tasks, and long-lived components.

Quick Start

Configure your DbContext to disable tracking by default, wire up the CLI migration tooling, and implement a dedicated migration runner for automated migrations.

Frequently Asked Questions about data-efcore-patterns

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

FAQPage Schema
How do I configure EF Core to use NoTracking by default for better read performance?

EF Core NoTracking is configured by setting the default query tracking behavior to NoTracking on your DbContext, boosting read performance while allowing explicit tracking when needed for write operations.

What is the best way to run EF Core migrations before app startup?

The best way to run EF Core migrations before app startup is using a dedicated migration service pattern, which isolates database seeding during tests and ensures the schema is updated reliably prior to application execution.

How do I safely perform bulk updates with EF Core without loading entities into memory?

You can safely perform bulk updates in EF Core using ExecuteUpdate and ExecuteDelete, which execute single SQL statements directly against the database, avoiding the need to load entities into memory.

Why does EF Core require an execution strategy for handling transient failures?

EF Core requires an execution strategy to gracefully retry transient failures, ensuring that database operations can recover from temporary connectivity issues while preserving data integrity.

How do I manage DbContext lifetime in dependency injection for background tasks?

Managing DbContext lifetime in dependency injection requires proper DI lifetime configuration for ASP.NET Core, background tasks, and long-lived components to prevent concurrency issues and ensure safe data access.

Can I manually edit EF Core migration files after generating them?

You should never edit EF Core migration files manually; maintaining a clean migration history ensures reliable deployments and prevents schema drift when using CLI tools to manage migrations.