dotnet-efcore-architecture

Design EF Core data layers with read/write separation and N+1 governance.

Updated Aug 16, 2025
One-click install
npx skills add https://github.com/dodyg/blue-nile-pds --skill dotnet-efcore-architecture-dodyg
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dotnet-efcore-architecture
Source: https://github.com/dodyg/blue-nile-pds/tree/main/.agents/skills/dotnet-efcore-architecture
Command: npx skills add https://github.com/dodyg/blue-nile-pds --skill dotnet-efcore-architecture-dodyg

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Designs EF Core data layer architecture with read/write separation, aggregate boundaries, and governance for N+1 queries, helping teams avoid architectural pitfalls and boilerplate.

Core Features & Use Cases

  • Read/Write Model Separation: maintain separate DbContext types for reads and writes to optimize performance and isolation.
  • Aggregate Boundaries: define aggregates with owned collections and clear persistence rules to ensure consistency.
  • Repository Policy: guidance on direct DbContext usage versus repository per aggregate root.
  • N+1 Query Governance: strategies to avoid N+1 patterns using eager loading and projection.
  • Row Limits and Pagination: enforce sensible limits and provide pagination strategies in data access.
  • Projection Patterns: project queries to DTOs to reduce data transfer and improve performance.

Quick Start

Initialize separate EF Core contexts (WriteDbContext and ReadDbContext), configure aggregate boundaries, and start using projection-based queries for reads.

Frequently Asked Questions about dotnet-efcore-architecture

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

FAQPage Schema
How do I separate read and write DbContext in EF Core?

To separate read and write DbContext in EF Core, initialize distinct context types for reads and writes. This read/write model separation optimizes performance and isolates transactional data access from projection-based reads.

What is the best way to avoid N+1 query problems in EF Core?

The best way to avoid N+1 query problems in EF Core is to apply N+1 governance strategies, specifically using eager loading for required relationships and projection patterns to fetch only necessary data.

How do I define aggregate boundaries when designing an EF Core data layer?

Define aggregate boundaries in an EF Core data layer by grouping entities with owned collections and establishing clear persistence rules. This ensures consistency and enforces transactional limits per aggregate root.

Should I use a repository pattern or direct DbContext with EF Core?

Decide between direct DbContext usage and a repository pattern by evaluating the repository policy. Use a repository per aggregate root to enforce boundaries, or use direct DbContext for simpler data access.

When should I use DTO projections for EF Core queries?

Use DTO projections for EF Core queries to reduce data transfer and improve performance. Projection patterns ensure you fetch only the necessary fields, avoiding lazy loading and inefficient data retrieval.

How do I enforce row limits and pagination in an EF Core data layer?

Enforce row limits and pagination in an EF Core data layer by applying sensible limits to queries and implementing pagination strategies. This prevents unbounded data retrieval and maintains data access performance.