efcore-patterns

Standardize EF Core query tracking, migrations, and resilient database updates.

Updated Jan 29, 2024
One-click install
npx skills add https://github.com/riandeoliveira/aspnet-template --skill efcore-patterns-riandeoliveira
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: efcore-patterns
Source: https://github.com/riandeoliveira/aspnet-template/tree/main/.claude/skills/efcore-patterns
Command: npx skills add https://github.com/riandeoliveira/aspnet-template --skill efcore-patterns-riandeoliveira

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps you avoid common EF Core performance and correctness pitfalls—especially around tracking, migrations, and inefficient query loading—so your application stays reliable as it grows.

Core Features & Use Cases

  • NoTracking by default: Improves read performance while ensuring writes work correctly via explicit updates or tracking.
  • Safe migration management: Guides you to create, remove, apply, and generate SQL scripts using EF Core CLI rather than manual edits.
  • Production-ready migration execution: Separates migrations from app startup using a dedicated migration service (including .NET Aspire orchestration).
  • Transient failure resilience: Uses CreateExecutionStrategy() for retryable operations that may fail temporarily.
  • Efficient bulk writes: Recommends ExecuteUpdateAsync / ExecuteDeleteAsync to avoid loading entities into memory.
  • Query splitting for navigation collections: Prevents cartesian explosion when loading multiple related collections with SplitQuery and targeted SingleQuery.

Quick Start

Apply EF Core best practices by configuring your DbContext for NoTracking-by-default, enabling query splitting, and running migrations through a dedicated migration service coordinated with Aspire.

Frequently Asked Questions about efcore-patterns

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

FAQPage Schema
How do I prevent cartesian explosion when loading multiple related collections in EF Core?

Prevent EF Core cartesian explosion by enabling query splitting with `SplitQuery` for multiple navigation collections, using targeted `SingleQuery` only when loading single related collections.

What's the best way to run EF Core migrations in production without coupling them to app startup?

Run EF Core migrations in production by separating them from app startup using a dedicated migration service, coordinating execution through .NET Aspire orchestration and CLI-driven idempotent SQL scripts.

How do I improve EF Core read performance without breaking write operations?

Improve EF Core read performance by configuring NoTracking as the default behavior, ensuring write operations still work correctly via explicit updates or selective tracking on modified entities.

Can I perform bulk updates in EF Core without loading entities into memory?

Perform EF Core bulk updates without loading entities into memory by using `ExecuteUpdateAsync` and `ExecuteDeleteAsync`, which execute directly against the database to optimize write performance.

Why does my EF Core migration execution fail on transient database errors?

EF Core migration execution fails on transient database errors when retry logic is missing; wrap operations in `CreateExecutionStrategy()` to handle temporary failures and ensure resilient database updates.

Do I need to use the EF Core CLI for safe migration management instead of manual edits?

Use the EF Core CLI for safe migration management to create, remove, apply, and generate SQL scripts, avoiding manual edits that cause migration mistakes and database drift.