database-performance

Optimizes EF Core and Dapper queries with read/write separation and batched SQL joins.

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

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps you eliminate common database performance issues like slow queries, excessive memory usage, and inefficient data loading by enforcing proven access patterns for EF Core and Dapper.

Core Features & Use Cases

  • Read/Write Separation (CQRS): Design distinct read projections and write commands so queries remain optimized and updates remain validation-focused.
  • N+1 and Join Discipline: Prevent N+1 query storms with batching or proper query shaping, and ensure joins happen in SQL rather than application-side filtering.
  • Guardrails for Safe Query Shape: Always project only needed columns, apply row limits, use AsNoTracking for read-only EF Core queries, avoid Cartesian explosions, and constrain string sizes.
  • Use Case Example: When building an order management feature, use purpose-built read stores for paginated order summaries and Dapper/EF Core projections for detailed views, while keeping writes strict and efficient.

Quick Start

Use the database-performance skill to review your EF Core and Dapper data-access methods and rewrite them to enforce read/write separation, row limits, AsNoTracking on reads, batching to avoid N+1, and SQL-side joins.

Frequently Asked Questions about database-performance

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

FAQPage Schema
How do I fix N+1 query problems in EF Core?

Fix N+1 query problems in EF Core by applying batched retrieval methods or proper query shaping to fetch related data in bulk, preventing query storms from executing individual queries per entity iteration.

What is the best way to separate database reads and writes in a CQRS architecture?

Separate database reads and writes in CQRS architectures by designing distinct read projections for optimized queries and strict write commands for validation-focused updates across your data access layer.

When should I use Dapper instead of EF Core for database queries?

Use Dapper instead of EF Core for database queries when building read-heavy paths requiring detailed views, keeping EF Core for strict write commands and validation-focused updates.

How do I prevent Cartesian explosions in EF Core read queries?

Prevent Cartesian explosions in EF Core read queries by applying projection-based queries with configurable row limits, selecting only needed columns, and using AsNoTracking for read-only paths.

Does EF Core support SQL-side joins to avoid application-side filtering?

EF Core supports SQL-side joins to avoid application-side filtering by enforcing query shaping patterns that ensure joins happen in SQL rather than in memory after data retrieval.

Why should I use AsNoTracking for read-only queries in EF Core?

Use AsNoTracking for read-only queries in EF Core to eliminate change tracking overhead, reducing memory usage and improving query performance for data access paths that never update entities.