Welcome!

SOA & WOA Authors: Peter Silva, Maureen O'Gara, Tony Bishop, Mark O'Neill, Yeshim Deniz

Related Topics: .NET, Silverlight

.NET: Article

A Nice Clean Way to Model Your Application's Data Layer

Using LINQ-to-SQL (Part 1)

2)  UPDATE A PRODUCT IN THE DATABASE
The code below demonstrates how to retrieve a single product from the database, update its price, and then save the changes back to the database:



Note: VB in the Orcas Beta 1 doesn't support Lambdas yet. It will, though, in Beta 2 when the query above can be rewritten to be more concise.

3)  INSERT A NEW CATEGORY & TWO NEW PRODUCTS INTO THE DATABASE
The code below demonstrates how to create a new category, and then create two new products and associate them with the category. All three are then saved in the database.

Note below how I don't need to manually manage the primary key/foreign key relationships. Instead, just by adding the Product objects into the category's "Products" collection, and then by adding the Category object into the DataContext's "Categories" collection, LINQ-to-SQL will know to persist the appropriate PK/FK relationships for me automatically.




More Stories By Scott Guthrie

Scott Guthrie, who will be keynoting October 20, 2008, was a founding member of the .NET Framework team and today runs the development teams that deliver the CLR, ASP.NET, Silverlight, WPF, IIS7, and the Visual Studio tools for web, WPF and Silverlight development. Previously the General Manager of Microsoft's Developer Division, he was promoted to Corporate Vice President in February '08.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.