Entity designer classes

Here are the concrete entity classes that the designer created to represent the model, and the model itself.

Image
Image

Image Put On Your Thinking Hat

Assuming that the recipe data has been retrieved from the database, how would you perform the following tasks based on the classes the designer created?

 

 

Iterate through each of the steps of the recipe stored in a variable named theRecipe.

 

 

Delete theRecipe.

 

 

Change the Headnote property of theRecipe.

 

 

Create a new recipe as part of the context.

 

 

Throw away any changes that have been made to theRecipe. (This one is tricky. Look at the methods of the ObjectContext class.)

 

 

Update the database.

 

 



Image Put On Your Thinking Hat

How’d you do?

Iterate through each of the steps of the recipe stored in a variable named theRecipe.

Image

foreach (RecipeStep s in theRecipe.RecipeSteps) {}

 

Delete theRecipe.

context.DeleteObject(theRecipe).

 

Change the Headnote property of theRecipe.

theRecipe.Headnote = "new headnote";

 

Create a new recipe as part of the context.

newRecipe = Recipe.CreateRecipe();

 

Throw away any changes that have been made to theRecipe. (This one is tricky. Look at the methods of the ObjectContext class.)

context.ApplyOriginalValues(theRecipe);

 

Update the database.

context.SaveChanges();

Image

Iterate through each of the steps of the recipe stored in a variable named theRecipe.

For Each s As RecipeStep In theRecipe.RecipeSteps
   ...
Next s

 

Delete theRecipe.

context.DeleteObject(theRecipe)

 

Change the Headnote property of theRecipe.

theRecipe.Headnote = "new headnote"

 

Create a new recipe as part of the context.

newRecipe = Recipe.CreateRecipe()

 

Throw away any changes that have been made to theRecipe. (This one is tricky. Look at the methods of the ObjectContext class.)

context.ApplyOriginalValues(theRecipe)

 

Update the database.

context.SaveChanges()


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

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