Model builder configurations
The Fluent API is pretty easy to use (once you get the hang of all those lambdas), but the OnModelBuilding()
method can quickly get pretty messy if you configure everything in the same method. Fortunately, the DbModelBuilder
exposes a collection property, Configurations
, that lets you separate the configurations for each type in a single class.
Just create a class that inherits from EntityTypeConfiguration<TEntity>
, where TEntity
is the type you want to configure.
public class MyConfig : EntityTypeConfiguration<MyType>{ public MyConfig() { // your Fluent configurations for this type go in the constructor }}
Get Fluent Entity Framework now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.