O'Reilly logo

Programming Entity Framework: Code First by Rowan Miller, Julia Lerman

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

Configuring Code First with the Fluent API

Configuring with Data Annotations is fairly simple and it may be just what you’re looking for. But Data Annotations only allow you to access a subset of the possible configurations (though much more than you’ve seen so far). The Fluent API, however, gives you access to even more, so you may prefer it for this reason.

There’s another reason why some developers will prefer the Fluent API over the annotations. While applying annotations to your pretty domain classes, they can definitely get more and more bogged down with the attributes. It’s one thing to be applying validation logic (Required, MaxLength, etc.), but as you learn more about configuration options, you’ll see that there are also many that are specifically about how the class maps to the database. If you prefer cleaner classes, you ...

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