25.1. LINQ to SQL

You may be thinking that we are about to introduce you to yet another technology for doing data access. In fact, what you will see is that everything covered in this chapter extends the existing ADO.NET data access model. LINQ to SQL is much more than just the ability to write LINQ statements to query information from a database. It provides a true object to a relational mapping layer, capable of tracking changes to existing objects and allowing you to add or remove objects as if they were rows in a database.

Let's get started and look at some of the features of LINQ to SQL and the associated designers on the way. For this chapter we're going to use the AdventureWorksLT sample database (downloadable from the MSFTDBProdSamples project at www.codeplex.com). We're going to end up performing a similar query to that used in Chapter 23, which was researching customers with a first name greater than or equal to five characters and the average order size for a particular product. In Chapter 23 the product was Milk, but because we are dealing with a bike company we will use the "HL Road Frame — Red, 44" product instead.

25.1.1. Creating the Object Model

For the purpose of this chapter we will be using a normal Visual Basic Windows Forms application from the New Project dialog. You will also need to create a Data Connection to the AdventureWorksLT database (covered in Chapter 21), which for this example is drnick.AdventureWorksLT.dbo. The next step is to add a LINQ to ...

Get Professional Visual Studio® 2008 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.