Choose a workflow & API

Image

You’ve had some experience with each of the Entity Framework workflows (Database-First, Model-First and Code-First) and both of the APIs. Now it’s time to decide how you’ll build the application. Here are some things to consider:

Image We don’t have a preexisting database, so there’s no compelling reason to use Database-First. There’s also no reason not to, if that seems the most comfortable way of working to you.

Image Microsoft recommends the DbContext API for new development. We’re not doing anything tricky that would require using the ObjectContext API, so there’s no reason not to follow that advice.

Image We’re going to want some sample data to work with. We can add that to the database, but it might be easier to “seed” it using an Initializer class. Do you think that has implications for which workflow you use?


Image What I’d Do

I’m a visual thinker and old database hand, so that means I almost always choose either Model-First or Database-First (and when I choose Database-First, I build most of my database schema in a database diagram). In this case, I think I’d probably go with Model-First, the DbContext, and build a DatabaseInitializer class to seed the data.



Image On Your Own

Think about your experience in this book with the three workflows and two APIs. Did anything strike you as particularly comfortable (or particularly tedious)?

I don’t see any compelling reason to choose any particular workflow or API in this situation, but I’m prepared to be wrong about that. Do you agree, or disagree?

Ponder, and pick...



Image Make A Note

There is another Entity Framework tool that you should be aware of, although we won’t be discussing it here. Code First Migrations will update a database schema when you update the class structure of your application. (Update, rather than re-create.)

Code First Migrations is primarily used when a database has already been deployed, and you don’t want to lose the existing data, but it can also be useful in a situation like ours when you’ve added sample data directly to the database.

If you’re interested, check out the Microsoft Data Developer Center for more details.


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

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