Книга: C# 2008 Programmer

Using the Object Relational Designer

Using the Object Relational Designer

To see how LINQ to SQL works, create a new Windows application using Visual Studio 2008.

First, add a new LINQ to SQL Classes item to the project. Use the default name of DataClasses1.dbml (see Figure 14-18).


Figure 14-18

In Server Explorer, open a connection to the database you want to use. For this example, use the pubs sample database. Drag and drop the following tables onto the design surface of DataClasses1.dbml:

? authors

? publishers

? titleauthor

? titles

Figure 14-19 shows the relationships among these four tables.


Figure 14-19

Now save the DataClasses1.dbml file, and Visual Studio 2008 will create the relevant classes to represent the tables and relationships that you just modeled. For every LINQ to SQL file you added to your solution, a DataContext class is generated. You can view this using the Class Viewer (View?Class View; see Figure 14-20). In this case, the name of the DataContext class is DataClasses1DataContext. The name of this class is based on the name of the .dbml file; if you named the .dbml file Pubs, this class is named PubsDataContext.


Figure 14-20 

Оглавление книги


Генерация: 1.263. Запросов К БД/Cache: 3 / 1
поделиться
Вверх Вниз