7. The Code First workflow

Are you proud of yourself? You should be. We’re a little over halfway through the book and you’ve learned how to create an Entity Data Model from a database, create a database from an Entity Data Model, manipulate the model in the Entity Model Designer, and even control the code the Designer creates at a very low level.

So what’s next, you ask? Why, the answer is obvious: It’s time to do without a model or the Designer at all. Well, sort of. If you choose the Code First Workflow that we’ll explore in this chapter, you won’t use the Designer and you won’t create an EDMX file. Instead, you’ll jump right into writing your code and using the DbContext API (which, as I’m sure you’ll remember, frees you from the requirement that your entity classes descend from EntityObject). When you do that,  Entity Framework will generate an in-memory EDM for you to work with at runtime. As we’ll see, it will even generate a database for you if one doesn’t already exist, which can make application deployment a whole lot easier (and yes, once again that’s the voice of experience.)

There is a little bit of magic going on when you work with Code First. But don’t worry if magic makes you nervous (it does me); you can take control of the model and how the Entity Framework interprets it. We’ll examine those conventions in this chapter and look at two ways of controlling them—data annotations and the Fluent API (no relation)—in the next.

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

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