8. Controlling The Schema

In the last chapter we explored the basic process for creating a database and an Entity Framework model starting with a class hierarchy rather than a model. We also took a look at some basic ways that you can control what Entity Framework will do (and when it will do it) when it creates the model (and possibly the database).

But as reasonable as the basic Code First conventions are, there are some things that Entity Framework can’t work out by itself. Complicated relationships, for example, or some database-specific attributes of the table fields. Fortunately, there are several ways you can control the ultimate database, and we’ll examine two in this chapter.

Data annotations are a set of metadata attributes that work just like other attributes (you may have used [Serializable()], for example). They’re easy to use, but they can’t do everything. The Fluent API, on the other hand, is extremely powerful, and it lets you confine your database-specific code to the DbContext class, which many people prefer. We’ll explore both techniques in this chapter.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset