data-database-performance

Separate read and write models in .NET data layers using EF Core and Dapper.

3|Updated Jan 24, 2024
One-click install
npx skills add https://github.com/akoken/dotfiles --skill data-database-performance
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: data-database-performance
Source: https://github.com/akoken/dotfiles/tree/main/config/.copilot/skills/data-database-performance
Command: npx skills add https://github.com/akoken/dotfiles --skill data-database-performance

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill blends proven data-access patterns to dramatically improve query performance by separating read models from write models, minimizing unnecessary tracking and data transfer.

Core Features & Use Cases

  • Separate read and write models to optimize queries and commands.
  • Enforce always-limited result sets with explicit pagination.
  • Use AsNoTracking for reads to avoid unnecessary change tracking overhead.
  • Avoid N+1 queries by embracing joins in SQL or batched reads.
  • Choose EF Core for writes and Dapper for reads to balance productivity and performance.

Quick Start

Create a pair of read/write stores per aggregate, wire them to your DbContext or data layer, enable AsNoTracking on read queries, and implement a paginated Get methods with a fixed limit.

Frequently Asked Questions about data-database-performance

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

FAQPage Schema
How do I improve EF Core query performance for high-traffic read operations?

Prevent N+1 queries in .NET data layers by performing joins in SQL rather than application code or using batched reads to retrieve related entities in a single database round-trip.

What is the best way to separate read and write models in a .NET data layer?

Separate read and write models by using EF Core for writes and Dapper for reads in web, API, and service components to balance productivity and query performance optimization.

Can I use Dapper for reads while keeping EF Core for writes in the same project?

Yes, you can use Dapper for reads and EF Core for writes within the same .NET project by creating a pair of read and write stores per aggregate to optimize queries and commands independently.

How do I prevent N+1 queries when fetching related data in EF Core?

Prevent N+1 queries in .NET data layers by performing joins in SQL rather than application code or using batched reads to retrieve related entities in a single database round-trip.

Do I need to implement pagination for read queries in .NET APIs?

Yes, you need to implement pagination for read queries to enforce always-limited result sets with configurable row limits, preventing excessive data transfer and ensuring stable API performance.