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

Using fluent configurations

The classes that you write to contain your Fluent API configurations are just classes. It’s unusual to include anything beyond Fluent API method calls, but there’s no reason that you can’t do so if it makes sense. There are two things to be aware of, though:

Image When you’re working inside the OnModelCreating() method, you start your method chain with the modelbuilder object that’s passed to the method, and then retrieve the entity:

Image       modelBuilder.Entity<Recipe>().HasKey(“RecipeId”);

or

       modelBuilder.Entity[Recipe]().HasKey(“RecipeId”) ...

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