O'Reilly logo

Programming Microsoft® LINQ in Microsoft .NET Framework 4 by Paolo Pialorsi and Marco Russo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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;
db.SubmitChanges();

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required