ef-core-advanced-patterns

Optimize EF Core data access with change tracking and PostgreSQL integration.

24|5|Updated Nov 28, 2025
One-click install
npx skills add https://github.com/thapaliyabikendra/ai-artifacts --skill ef-core-advanced-patterns
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ef-core-advanced-patterns
Source: https://github.com/thapaliyabikendra/ai-artifacts/tree/main/.claude/skills/ef-core-advanced-patterns
Command: npx skills add https://github.com/thapaliyabikendra/ai-artifacts --skill ef-core-advanced-patterns

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Master EF Core advanced patterns including change tracking optimization, loading strategies (eager/explicit/lazy), query splitting, compiled queries, batch operations, optimistic concurrency, performance improvements, and PostgreSQL-specific features for .NET applications.

Core Features & Use Cases

  • Change Tracking Optimization: No-Tracking queries, identity resolution, and efficient change manager usage.
  • Loading Strategies: Eager, Explicit, and Lazy loading for precise data fetch planning.
  • Query Splitting: Split queries to avoid cartesian explosion.
  • Compiled Queries & Batch Operations: Performance-focused query execution.
  • Concurrency & PostgreSQL: Optimistic concurrency and PostgreSQL-specific features.
  • Debugging: Techniques to identify and fix slow EF Core queries.

Quick Start

Refactor a slow data access path by enabling NoTracking for reads and using split queries where appropriate.

Frequently Asked Questions about ef-core-advanced-patterns

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

FAQPage Schema
How do I optimize EF Core queries to eliminate N+1 problems and improve performance?

N+1 query problems occur when loading related entities triggers additional database calls. Use eager loading with Include(), explicit loading, or split queries to fetch related data efficiently in fewer round trips, reducing query overhead and improving application performance.

What's the difference between eager, explicit, and lazy loading in Entity Framework Core?

Eager loading fetches related data upfront with Include(); explicit loading retrieves data on demand using Load(); lazy loading automatically loads data when accessed. Each suits different scenarios: eager for known relationships, explicit for conditional loading, and lazy for transparent but unpredictable access patterns.

When should I use AsNoTracking for EF Core queries?

Use AsNoTracking on read-only queries where you don't need change tracking, reducing memory overhead and improving throughput. It's ideal for reporting, bulk reads, and high-volume scenarios where entity state management adds unnecessary cost without providing value.

How do I handle cartesian explosion when joining multiple collections in EF Core?

Split queries break multi-collection joins into separate queries to avoid cartesian explosion, where result sets multiply unexpectedly. Use AsSplitQuery() to execute multiple focused queries instead of one complex join, preserving data accuracy and query efficiency.

What PostgreSQL-specific features does EF Core support for advanced data access patterns?

EF Core leverages PostgreSQL features including array types, JSON operators, and native pagination for optimized queries. These enable specialized patterns aligned with PostgreSQL strengths, supporting scalable read-heavy workloads and complex data structures.

How do I implement optimistic concurrency control in EF Core applications?

Optimistic concurrency uses version tokens or timestamps to detect conflicts when multiple clients modify the same entity. Configure concurrency tokens with HasConcurrencyToken(), catch DbUpdateConcurrencyException on SaveChanges(), and implement retry logic to handle contention safely.