200Microsoft Visual Studio 2010: A Beginner’s Guide
Handling Data with LINQ to SQL
The LINQ to SQL provider allows you to communicate with SQL Server databases. There are many other types of providers, such as LINQ to Entities for generic databases (which includes SQL Server), LINQ to XML for XML data sources, and LINQ to Oracle for Oracle databases. The preceding section showed you how to use the
Setting Up LINQ to SQL
Setting up LINQ to SQL involves running the LINQ to SQL Wizard and adding classes and methods. Behind the scenes, LINQ to SQL generates code, saving you a lot of work. The result of setting up LINQ to SQL is that you will have a data model, which is an environment with classes that you can use to query and modify database data and call methods for invoking stored procedures.
Before setting up LINQ to SQL, you’ll need to create a project (a Console project for the purposes of this chapter). See Chapter 5 if you need a refresher on how to set up a Console project. Select Add New Item, select LINQ to SQL Classes, name the file MyShop.dbml, and click Add. This will show you the LINQ to SQL Designer, with two surfaces for classes and methods. Figure
a couple of classes and a method.