database-performance

Optimizes database access patterns using EF Core and Dapper with CQRS read/write separation.

Updated Mar 8, 2026
One-click install
npx skills add https://github.com/AGIBuild/dotnet.CI.template --skill database-performance-agibuild
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: database-performance
Source: https://github.com/AGIBuild/dotnet.CI.template/tree/main/.cursor/skills/database-performance
Command: npx skills add https://github.com/AGIBuild/dotnet.CI.template --skill database-performance-agibuild

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Slow queries, N+1 problems, unbounded result sets, and poorly structured data access layers degrade application performance and are hard to fix retroactively. This Skill provides concrete patterns for building efficient data access layers in .NET from the start. ## Core Features & Use Cases - Read/Write Model Separation: Implements CQRS-style architecture with dedicated read stores returning optimized projections and write stores accepting strongly-typed commands. - Query Optimization Patterns: Covers AsNoTracking for reads, row limits on every query, avoiding N+1 queries with Include or batch queries, and preventing Cartesian explosions with AsSplitQuery. - EF Core vs Dapper Guidance: Provides decision criteria for choosing between EF Core and Dapper, including using both together for writes and reads respectively. - Use Case: When building a new order management endpoint, apply these patterns to create a paginated read store with cursor-based limits and a separate write store, avoiding the generic repository anti-pattern. ## Quick Start Review my data access layer code and apply database performance patterns to eliminate N+1 queries and add row limits.

Frequently Asked Questions about database-performance

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

FAQPage Schema
How do I avoid N+1 queries in EF Core?▼

Use the Include method to eager-load related entities in a single query, or use AsSplitQuery when including multiple collections to avoid Cartesian explosions. With Dapper, fetch parent and child rows in one batch query and join them in memory.

When should I use Dapper vs EF Core?▼

Use EF Core for simple CRUD and domain-heavy writes with validation, and Dapper for complex read queries, reporting, and bulk operations. Both can coexist in one project, with EF Core handling writes and Dapper handling reads.

Does AsNoTracking improve EF Core query performance?▼

Yes, AsNoTracking disables change tracking, which reduces memory usage and speeds up read-only queries. You can set NoTracking as the default behavior in OnConfiguring and explicitly opt into tracking with AsTracking when modifying entities.

Why are generic repositories considered an anti-pattern?▼

Generic repositories hide query complexity, prevent query-specific optimization, offer no way to enforce row limits, and encourage fetching too much data. Purpose-built read and write stores with explicit methods make performance characteristics visible and controllable.

How do I prevent Cartesian explosion with multiple Includes?▼

Use AsSplitQuery to split multiple collection Includes into separate queries, avoiding row multiplication. Alternatively, use explicit projection with Select to fetch only the needed columns and limited related items.