Updating the model

Image

Stuff changes. It’s a basic fact of our profession, and you’ve learned to expect and plan for that, right? Right? Well, even if you haven’t, the designers at Microsoft have, and they’ve built the Entity Model Wizard to allow you to be able to update the model when the database schema changes, or when you need to add additional database objects to your model. To see how that works, let’s start by making a minor change to the database:

Image

In the Server Explorer (choose Server Explorer from the Windows menu if it’s not visible), expand the connection to the Recipe database that Visual Studio created for you. Expand the Tables node and then right-click the Recipe table and choose Open Table Definition.

Change the name of the Title field to RecipeName, save the change, and then close the tab.

Image
Image

Let’s make one more change: Select the WeightByUnit table in the Server Explorer and press the Delete key to delete it from the database. Visual Studio will ask you to confirm the change. Click OK.


Image On Your Own

When you right-click on a blank area of the designer window, one of the options is “Update Model from Database...” What do you think will happen if you choose it?

 

We changed the name of a field in the Recipe table. Do you expect the name to change in the model? (Remember that we changed the names of the association properties in the RecipeIngredient entity. What do you think will happen to those?)

We deleted a table from the database. What do you expect to happen to it in the model?


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

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