To illustrate this, let??™s modify the directory example from earlier in this chapter. One of the great things
about LINQ is that it enables you easily to ??????map??™??™ object-oriented objects within your .NET programming
language to a database and the objects within a relational database. That means you can access those
relational objects in a strongly typed, object-oriented manner.
8
Chapter 1: Project LINQ
To do this, a mapping to the database needs to be made, and that is accomplished by creating and
declaring two classes. Those classes map the relational objects into the object-oriented world. The first
class maps the actual database:
[Database(Name="AdventureWorks")]
public class AdventureWorks : DataContext
{
public AdventureWorks(string connection) : base(connection) {}
public Table
DirectoryInformation;
}
The second class maps the table and columns of the table you want to access:
[Table(Name="DirectoryInformation")]
public class DirectoryInformation
{
[Column(DbType="varchar(50)")]
public string DirectoryName;
[Column(DbType = "varchar(255)")]
public string DirectoryDescription;
}
The class name maps to the table in the database you want to access, and the columns are mapped by
adding metadata to a couple of variables.
Pages:
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44