Scott Klein
"Professional LINQ"
GetTable
();
var query =
contact.Join(employee, con => con.ContactID,
emp => emp.ContactID, (con, emp) =>
new { con = con, emp = emp})
.Where(c => c.con.FirstName.StartsWith("S"))
.Where(c => c.emp.HireDate.Year > 1999)
.OrderBy(c => c.con.LastName)
.OrderBy(c => c.con.FirstName)
.Select(o => new
{ o.emp.EmployeeID, o.con.LastName, o.con.FirstName,
o.emp.Title, o.con.EmailAddress, o.emp.HireDate} );
foreach (var item in query)
91
Part I: Introduction to Project LINQ
listBox1.Items.Add(item.FirstName
+ " " + item.LastName
+ " " + item.Title
+ " " + item.EmailAddress
+ " " + item.HireDate);
This code accomplishes the exact same thing as the preceding code, but usesmethod syntax. This example
is here to illustrate the different ways you can use the LINQ standard query operators.
Summary
This chapter introduced you to LINQ??™s standard query operators. Without them, LINQ doesn??™t happen.
The chapter provides you with a good foundation in and understanding of their functionality, which will
be helpful because the rest of this book utilizes the information found in this chapter.
Pages:
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178