Optimization of Compiled Models in EF Core
David Shergilashvili
Head of Software Development Unit at TeraBank | ?? T-Shaped .NET Solution Architecture
Introduction
Compiled models represent a significant optimization in Entity Framework Core, especially for large and complex data models. This article explores how compiled model support has evolved in EF Core versions 6 through 9.
EF Core 6: Manual Compiled Models
In EF Core 6, compiled models were available but required manual configuration and generation.
Process:
Generate the model using the command:
Use the generated model:
Advantages:
Disadvantages:
EF Core 8: Improved Compiled Models
EF Core 8 brought improvements and simplifications to compiled models.
Enhancements:
Example:
领英推荐
Advantages:
EF Core 9: Automatic Compiled Models, MSBuild Integration
EF Core 9 represents a significant leap in automating compiled models.
New Features:
Usage:
No explicit configuration is needed in the code:
Advantages:
Performance Comparison
Assuming a model with 100 entities:
Migrating Between Versions
Conclusion
The evolution of compiled models in EF Core from version 6 to 9 demonstrates significant progress in terms of automation and performance. The introduction of automatically compiled models and MSBuild integration in EF Core 9 represents a major step forward, allowing developers to benefit from compiled models with minimal effort.