EF Core (.NET 10)
Core Principles
- EF Core is the default ORM — Use it unless you have a specific reason not to (extreme perf, legacy DB without FK constraints). See ADR-003.
- DbContext is a unit of work — Don't wrap it in another UoW abstraction. EF Core already implements Unit of Work and Repository patterns internally.
- Queries should be projections — Use
.Select()to project into DTOs instead of loading full entities. This avoids over-fetching and N+1 issues. - Migrations are code — Treat them like any other source code. Review them, test them, never auto-apply in production.
Patterns
DbContext Configuration
Use IEntityTypeConfiguration<T> to keep entity configs separate and discoverable.
Registration
Query Projections (Avoid Over-Fetching)
Pagination
ExecuteUpdateAsync / ExecuteDeleteAsync
Bulk operations that bypass change tracking for better performance.
Interceptors
Use interceptors for cross-cutting concerns like audit trails and soft deletes.
Compiled Queries
Use for hot-path queries that execute frequently with the same shape.
