Improvement of Model Building Conventions in EF Core
David Shergilashvili
???? Engineering Manager | ??? .NET Solution Architect | ?? Software Developer | ?? Herding Cats and Microservices
Introduction
Model building conventions play a crucial role in Entity Framework Core, as they define how the data model should be automatically constructed. This article explores how these conventions have improved across EF Core versions 6 through 9.
EF Core 6: Limited Conventions
In EF Core 6, model-building conventions were functional but limited.
Key Conventions:
Example:
In this case, EF Core would automatically discover Id as the primary key and BlogId as a foreign key.
Limitations:
EF Core 8: Extended Conventions
EF Core 8 brought significant improvements and extensions to conventions.
New and Improved Conventions:
领英推荐
Example:
EF Core 8 now automatically supports complex types (BlogMetadata) and indexes (with the [Index] attribute).
EF Core 9: More Extensible Conventions
EF Core 9 further expands the capabilities of conventions and options for customizing them.
New Features:
Example of a User-Defined Convention:
This convention will automatically add prefixes to all table and column names.
Automatic Support for JSON Data:
EF Core 9 will automatically support JSON data in the Metadata property, using appropriate conventions.
Migrating Between Versions
Conclusion
The evolution of model-building conventions in EF Core from version 6 to 9 demonstrates significant progress in terms of flexibility and functionality. The extensible conventions introduced in EF Core 9 allow developers to customize the model-building process to their needs more effectively, reducing the need for manual configuration and increasing productivity.