EF Core Standards
Purpose
EF Core is an approved secondary persistence technology for AIC systems where a relational database is the right architectural choice. MongoDB remains the default primary persistence layer.
EF Core is powerful but must be used deliberately. AIC standards prevent hidden performance issues, migration risk, and accidental API leakage.
Mandatory Rules
Do not return EF entities directly from public APIs.
Do not use lazy loading by default.
Use async database calls.
Pass cancellation tokens.
Use migrations under source control.
Review important generated SQL.
Keep
DbContextscoped.Avoid long-lived
DbContextinstances.Use transactions where consistency requires them.
DbContext Registration
Use pooling only after reviewing state and tenant implications.
Entity Configuration
Prefer explicit configuration:
Query Rules
Project only required fields.
Use
AsNoTrackingfor read-only queries.Avoid client-side evaluation surprises.
Avoid N+1 queries.
Limit result sets.
Use pagination.
Index columns used for filtering and sorting.
Save Rules
Validate before persistence.
Use transactions for multi-aggregate consistency where necessary.
Handle concurrency exceptions.
Capture audit fields consistently.
Do not hide database failures.
Migration Checklist
Migration reviewed by developer and database-aware reviewer.
Destructive change identified.
Rollback or fix-forward approach documented.
Data migration risk assessed.
Index impact assessed.
Production deployment order understood.
Was this helpful?

