Chapter 6. LINQ to SQL: Managing Data

The previous chapter primarily covered how you can read data with LINQ to SQL. The next step is understanding how to modify the data in a database using LINQ to SQL.

Luckily, by using entities, updating a column for a specific row in a table is as simple as changing a property of an entity instance. For example, the following code reads a product, increases its price by 5 percent by modifying the UnitPrice property, and then applies the in-memory changes to the database by calling SubmitChanges:

Product product = db.Products.Single(p => p.ProductID == 42);
product.UnitPrice *= 1.05M;

In this chapter, you will see how to handle entity updates applied to the database, and investigate concurrency, ...

Get Programming Microsoft® LINQ in Microsoft .NET Framework 4 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.