7.1. Setting Up the LINQ Examples

This chapter walks you through LINQ examples, using arrays, collections, XML, and relational data. To avoid frustration with the LINQ to SQL examples, replicate the environment. This section helps you get started on the right foot.

7.1.1. Creating the DataContext object

Some of the examples in this chapter require the Northwind database and the DataContext object that supports LINQ queries. Follow these steps to generate the DataContext object for the Northwind database:

  1. Add the sample Northwind database and a working data connection to your project (see Chapter 6).

  2. Add a LINQ to SQL Classes file called NWDataClasses.dbml to your project (FileNew FileLINQ to SQL ClassesAdd).

    If you're prompted to put the file in a special App_Code folder, click Yes. VWD creates the folder.

    The split-page object relational designer appears.

  3. From Database Explorer (Server Explorer in non-Express versions), expand the Tables node.

  4. As shown in Figure 7-1, drag the Categories, Order Details, Products, and Suppliers table names from Database (or Server) Explorer and drop them on the left-hand (larger) design surface of NWDataClasses.dbml.

    This generates the DataContext code in ...

Get ASP.NET 3.5 For Dummies® 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.