Tooluck logoTooluck
SKILL.md

efcore-patterns

Agent skill fromAaronontheweb/dotnet-skills

Entity Framework Core best practices including NoTracking by default, query splitting for navigation collections, migration management, dedicated migration services, and common pitfalls to avoid.

How to install efcore-patterns

install efcore-patterns
# install the dotnet-skills pack with the skills CLI
npx skills add Aaronontheweb/dotnet-skills

# or add only this skill to Claude Code: copy the folder

skills/efcore-patterns/

# into

~/.claude/skills/efcore-patterns/ (all projects)

.claude/skills/efcore-patterns/ (one project)

skills/efcore-patterns/SKILL.md

MITFull file
1# Entity Framework Core Patterns
2
3## When to Use This Skill
4
5Use this skill when:
6- Setting up EF Core in a new project
7- Optimizing query performance
8- Managing database migrations
9- Integrating EF Core with .NET Aspire
10- Debugging change tracking issues
11- Loading multiple navigation collections efficiently (query splitting)
12
13## Core Principles
14
151. **NoTracking by Default** - Most queries are read-only; opt-in to tracking
162. **Never Edit Migrations Manually** - Always use CLI commands
173. **Dedicated Migration Service** - Separate migration execution from application startup
184. **ExecutionStrategy for Retries** - Handle transient database failures
195. **Explicit Updates** - When NoTracking, explicitly mark entities for update
20
21---
22
23## Pattern 1: NoTracking by Default
24
25Configure your DbContext to disable change tracking by default. This improves performance for read-heavy workloads.
26
27```csharp
28public class ApplicationDbContext : DbContext
29{
30 public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
31 : base(options)
32 {
33 // Disable change tracking by default for better performance on read-only queries
34 // Use .AsTracking() explicitly for queries that need to track changes
35 ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
36 }
37
38 public DbSet<Order> Orders => Set<Order>();
39 public DbSet<Customer> Customers => Set<Customer>();
40}
41```
42
43### When NoTracking is Active
44
45**Read-only queries work normally:**
46…

Excerpt shown under the repository's MIT license.

More skills in dotnet-skills

Newsletter

Join the Community

Subscribe to our newsletter for the latest news and updates