This example is just to whet your appetite. There??™s not a lot of explanation here because there
are more than a handful of chapters that discuss object mapping and querying in much
greater detail.
Once the mapping is complete, the data can be queried. And not just queried, but queried using
strongly typed syntax.
The first line of the following code accesses the database as an object, creating a new instance of the class
previously defined, a strongly typed connection. Once you have the connection, you can access the table
and data in a strongly typed fashion, as shown in the second and third lines. Notice that the columns in
the table are accessed via dot notation directly in C#.
AdventureWorks db = new AdventureWorks("Integrated Security=sspi");
foreach (var item in db.DirectoryInformation)
listBox1.Items.Add(item.DirectoryName + " " +
item.DirectoryDescription);
Executing this code returns the data from the DirectoryInformation table and lists both the directory
name and description in a list box.
To make it more interesting, take the directory example from the beginning of the chapter and modify it
to join to this query.
Pages:
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45