This appendix provides syntax summaries for the most useful LINQ methods. For more detailed information, see Chapter 21, "LINQ."
The following text shows the typical syntax for a LINQ query:
From ... Where ... Order By ... Select ...
The following sections describe these four basic clauses. The sections after those describe some of the other most useful LINQ clauses.
The From clause tells where the data comes from and defines the name by which it is known within the LINQ query.
Dim query1 = From cust As Customer In all_customers Dim query2 = From stu In students, score In TestScores
Usually, if you select data from multiple sources, you will want to use a Where clause to join the results from the sources.
The Where clause applies filters to the records selected by the From clause. The syntax is:
Use comparison operators (>, <, =), logical operators (Not, Or, AndAlso), object methods (ToString, Length), and functions to build complex conditions.
For example, the following query selects student and test score data, matching students to their test scores:
Dim query = From stu In students, score In TestScores Where stu.StudentId = score.StudentId
The following example selects only students with last names starting with S:
Dim query = From stu In students, score In TestScores Where stu.StudentId = score.StudentId AndAlso stu.LastName.ToUpper.StartsWith("S")
The Order ...