O'Reilly logo

Fluent Entity Framework by Rebecca M. Riordan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

Image

public class MyConfig : EntityTypeConfiguration<MyType>{ public MyConfig() {  // your Fluent configurations for this type go in the constructor }}

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required