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”) ...

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.