- Introduction
- Creating a Conceptual Model with the Model Wizard
- Querying with Entity SQL
- Updating Data with Entity SQL
- Summary
Updating Data with Entity SQL
Each ObjectContext knows about the data it has. The easiest way to modify data is to select the data you want, modify the relevant objects, and tell the ObjectContext to save the changes—ObjectContext.SaveChanges.
Listing 3 uses eSQL to select Alfreds Fütterkiste. The ContactName is changed and the modifications are written back to the database.
Listing 3 Select the data you want to change, modify the relevant object's properties, and save the changes through the ObjectContext.
northwindEntities entities = new northwindEntities(); ObjectQuery<Customers> customers = new ObjectQuery<Customers>( "SELECT VALUE Customer FROM northWindEntities.Customers As Customer " + "WHERE Customer.CustomerID = 'ALFKI'", entities); // was Maria Anders customers.First().ContactName = "Paul Kimmel"; entities.SaveChanges();
There's a lot more to eSQL and entities, but this will get you started with the basics. Check back with InformIT for updates and more examples on Entity SQL and LINQ to Entities.