efcore-patterns
EF Core best practices covering NoTracking queries, migration management, query splitting, and change tracking patterns.
- Configure NoTracking by default for read-heavy workloads; explicitly use
.AsTracking()or.Update()for mutations to avoid silent failures - Never manually edit migration files; always use CLI commands (
dotnet ef migrations add/remove/script) to manage schema changes safely - Implement a dedicated migration service with .NET Aspire to separate database setup from application startup and ensure migrations complete before the app runs
- Use
ExecuteUpdateAsync()andExecuteDeleteAsync()for bulk operations instead of loading entities into memory; applyCreateExecutionStrategy()for transient failure handling - Enable
QuerySplittingBehavior.SplitQueryglobally to prevent cartesian explosion when loading multiple navigation collections, overriding per-query withAsSingleQuery()when appropriate
Entity Framework Core Patterns
When to Use This Skill
Use this skill when:
- Setting up EF Core in a new project
- Optimizing query performance
- Managing database migrations
- Integrating EF Core with .NET Aspire
- Debugging change tracking issues
- Loading multiple navigation collections efficiently (query splitting)
Core Principles
- NoTracking by Default - Most queries are read-only; opt-in to tracking
- Never Edit Migrations Manually - Always use CLI commands
- Dedicated Migration Service - Separate migration execution from application startup
- ExecutionStrategy for Retries - Handle transient database failures
- Explicit Updates - When NoTracking, explicitly mark entities for update
More from aaronontheweb/dotnet-skills
modern-csharp-coding-standards
Write modern, high-performance C# code using records, pattern matching, value objects, async/await, Span<T>/Memory<T>, and best-practice API design patterns. Emphasizes functional-style programming with C# 12+ features.
1.3Kcsharp-concurrency-patterns
Choosing the right concurrency abstraction in .NET - from async/await for I/O to Channels for producer/consumer to Akka.NET for stateful entity management. Avoid locks and manual synchronization unless absolutely necessary.
967dotnet-project-structure
Modern .NET project structure including .slnx solution format, Directory.Build.props, central package management, SourceLink, version management with RELEASE_NOTES.md, and SDK pinning with global.json.
272api-design
Design stable, compatible public APIs using extend-only design principles. Manage API compatibility, wire compatibility, and versioning for NuGet packages and distributed systems.
263type-design-performance
Design .NET types for performance. Seal classes, use readonly structs, prefer static pure functions, avoid premature enumeration, and choose the right collection types.
262dependency-injection-patterns
Organize DI registrations using IServiceCollection extension methods. Group related services into composable Add* methods for clean Program.cs and reusable configuration in tests.
257