Summary
Implement EF Core 9.0 auto-compiled models feature to improve application startup performance by automatically detecting and using compiled models without requiring manual configuration.
Background
EF Core 9.0 introduces auto-compiled models that can significantly improve startup time for applications with large models (100s or 1000s of entity types). This feature eliminates the need to manually configure compiled models and automatically detects when a compiled model is available.
Key Benefits:
- ✅ Faster startup time - Heavy lifting of processing and compiling LINQ queries into SQL no longer happens at application startup
- ✅ Automatic detection - No need to manually call
.UseModel() when the compiled model is in the same project/assembly
- ✅ MSBuild integration - Can automatically update compiled models when the model project is built
- ✅ Improved performance - Each query's interceptor contains finalized SQL and optimized materialization code
Technical Details
What's New in EF Core 9.0:
- Auto-detection: Compiled models are automatically detected and used when in the same project/assembly as the DbContext
- MSBuild integration: Can automatically regenerate compiled models during build process
- Simplified workflow: No longer requires manual
.UseModel(MyCompiledModels.BlogsContextModel.Instance) calls
Before (EF Core 8.x):
// Manual command required
dotnet ef dbcontext optimize
// Manual configuration required
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder.UseModel(MyCompiledModels.BlogsContextModel.Instance);
After (EF Core 9.0):
// Automatic detection - no manual configuration needed
// Just run: dotnet ef dbcontext optimize
// Or use MSBuild integration for automatic builds
Acceptance Criteria
Phase 1: Basic Auto-Compiled Models
Phase 2: MSBuild Integration (Optional)
Phase 3: Documentation & Guidelines
Implementation Notes
Performance Considerations:
- Most beneficial for applications with large models (100s or 1000s of entity types)
- Reduces startup time by pre-compiling LINQ query processing
- Generated interceptors contain optimized SQL and materialization code
- Uses unsafe accessors for efficient object materialization
Compatibility:
- Requires EF Core 9.0+
- Works with .NET 8+ (EF 9 targets .NET 8)
- Auto-detection only works when DbContext and compiled model are in same assembly
Example Generated Code:
The feature generates interceptors with embedded SQL and materialization code:
// Pre-compiled SQL
var relationalCommandTemplate = new RelationalCommand(
materializerLiftableConstantContext.CommandBuilderDependencies,
"SELECT [b].[Id], [b].[Name]\nFROM [Blogs] AS [b]\nWHERE [b].[Name] = N'foo'",
new IRelationalParameter[] { });
// Optimized materialization using unsafe accessors
var instance = new Blog();
UnsafeAccessor_Blog_Id_Set(instance) = dataReader.GetInt32(0);
UnsafeAccessor_Blog_Name_Set(instance) = dataReader.GetString(1);
Resources
Priority
Medium - Performance enhancement that provides measurable startup improvements for applications with large EF models.
Labels
enhancement
ef-core
performance
dotnet-9
This issue implements the EF Core 9.0 auto-compiled models feature as described in the official Microsoft documentation.
Summary
Implement EF Core 9.0 auto-compiled models feature to improve application startup performance by automatically detecting and using compiled models without requiring manual configuration.
Background
EF Core 9.0 introduces auto-compiled models that can significantly improve startup time for applications with large models (100s or 1000s of entity types). This feature eliminates the need to manually configure compiled models and automatically detects when a compiled model is available.
Key Benefits:
.UseModel()when the compiled model is in the same project/assemblyTechnical Details
What's New in EF Core 9.0:
.UseModel(MyCompiledModels.BlogsContextModel.Instance)callsBefore (EF Core 8.x):
After (EF Core 9.0):
Acceptance Criteria
Phase 1: Basic Auto-Compiled Models
.UseModel()configurationPhase 2: MSBuild Integration (Optional)
Phase 3: Documentation & Guidelines
Implementation Notes
Performance Considerations:
Compatibility:
Example Generated Code:
The feature generates interceptors with embedded SQL and materialization code:
Resources
Priority
Medium - Performance enhancement that provides measurable startup improvements for applications with large EF models.
Labels
enhancementef-coreperformancedotnet-9This issue implements the EF Core 9.0 auto-compiled models feature as described in the official Microsoft documentation.