Contact")]
public class Contact
{
[Column(DBType = "nvarchar(8) not null")]
public string Title;
[Column(DBType = "nvarchar(50) not null")]
public string FirstName;
47
Part I: Introduction to Project LINQ
[Column(DBType = "nvarchar(50) not null")]
public string MiddleName;
[Column(DBType = "nvarchar(50) not null")]
public string LastName;
[Column(DBType = "nvarchar(50) not null")]
public string EmailAddress;
[Column(DBType = "int")]
public int EmailPromotion;
}
}
Place the following code in the click event for the Close button:
Application.Exit();
Next, in the click event for the Query Method button, place the following code:
DataContext context = new DataContext("Initial Catalog=AdventureWorks;@@ta
Integrated Security=sspi");
Table
contact = context.GetTable();
var query =
from c in contact
where c.FirstName.StartsWith("S")
&& c.LastName.StartsWith("K")
orderby c.LastName
select c;
foreach (var item in query)
listBox1.Items.Add(item.FirstName + " " + item.LastName + " " +
item.EmailAddress);
This code creates a query expression filtering all contacts whose first name begins with the letter S and
whose last name begins with the letter K, all sorted by the contacts??™ last name.
Pages:
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114