Welcome!

SOA & WOA Authors: Yeshim Deniz, Salvatore Genovese, Mark O'Neill, Irfan Khan, Vikas Aggarwal

Related Topics: .NET, Silverlight

.NET: Article

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

Using LINQ-to-SQL (Part 1)

4)  DELETE PRODUCTS FROM THE DATABASE
The code below demonstrates how to delete all Toy products from the database:



5)  CALL A STORED PROCEDURE
The code below demonstrates how to retrieve Product entities not using LINQ query syntax, but rather by calling the "GetProductsByCategory" stored procedure we added to our data model. Note that once I retrieve the Product results, I can update or delete them and then call db.SubmitChanges() to persist the modifications back to the database.


VB:

6)  Retrieve Products with Server-side Paging
The code below demonstrates how to implement efficient server-side database paging as part of a LINQ query. By using the Skip() and Take() operators below, we'll only return 10 rows from the database - starting with row 200.



Summary
LINQ-to-SQL provides a nice clean way to model the data layer of your application. Once you've defined your data model you can easily and efficiently perform queries, inserts, updates, and deletes against it. Hopefully the introduction and code samples above have helped whet your appetite to learn more. I'll be continuing this series of exploring LINQ-to-SQL in more detail.

•  •  •

To read more on LINQ-to-SQL, visit Scott Guthrie's blog at http://weblogs.asp.net/scottgu.

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.