This same query in T-SQL would be the following:
SELECT FirstName, LastName, EmailAddress
FROM Contact
WHERE LEFT(FirstName, 1) = ???S??™
ORDER BY LastName
The differences are that in SQL this query would be executed internally, following the steps described
earlier. With LINQ, the query does not need to go through the rewriting process. Also, the same LINQ
operators work against other data sources.
With this in mind, the next section explores query operations and expressions to help you more fully
understand LINQ query concepts.
Query Concepts
You have seen multiple examples of LINQ queries so far in this book. Now you??™ll explore the basic
layout and syntax, as well as the different kinds of operations that can take place in a query. (Chapter 4
discusses in detail the many standard query operators that are at your disposal when writing LINQ query
expressions.) For this discussion, the following query will be used:
from c in contact
where c.FirstName.StartsWith("S")
orderby c.LastName
select c
In a LINQ query, the first clause is from, which specifies the source of the data.
Pages:
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95