For example, the
following line groups the results of the query by contact country:
group c by c.Country
The final step is to project (select) the data using the select clause. By projecting the data, you are
defining the results as something other than a simple copy of the original source. For example, if the
data source returns FirstName, LastName, EmailAddress, Title, MiddleName, and City, but the select
clause only produces the FirstName and LastName properties in the results, that is a projection.
38
Chapter 3: LINQ Queries
The select clause enables you to determine the shape of each object that is returned by the query. Here??™s
an example that returns the entire collection object:
from c in contact
where c.FirstName.StartsWith("S")
orderby c.LastName
select c
To select a single property, simply select that property, like this:
from c in contact
where c.FirstName.StartsWith("S")
orderby c.LastName
select c.LastName
Selecting a single result (column/property), in this case a string value, changes the result type from an
IEnumerable collection of type contact in the first example to an IEnumerable of String in this example
because only a single string value is being returned.
Pages:
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98