Performing Other Data Operations

Now that we have consolidated the code that accesses the data model, we can add pages to our web application to handle other data operations. In the following sections, you will learn how to create, modify, and delete data from the database using the Entity Framework.

Adding Data

Adding new data using the entity data model is a four-step process:

  • Create a new instance of the entity class that represents rows of the table of interest.
  • Set values for the parameters of the entity object we created.
  • Add the object to the collection of similar objects maintained by the entity context.
  • Call the SaveChanges method to write the change to the database.

Because we have consolidated our data-access code, these four steps ...

Get Applied ASP.NET 4 in Context now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.