A single value is considered a
query that returns a Count or Max, for example. You can also force an immediate execution of a query by
calling the ToList or ToArray methods. The following example illustrates a query that returns a single
value, thus executing immediately:
var query = (from o in Order
where CustomerID = 2
select o).Count();
This query counts the number of orders from the Sales.SalesOrderHeader table in the AdventureWorks
database, where the CustomerID in that table is 2. Likewise, instead of getting a count of orders, you can
also send the query results to a list or array:
var query = (from o in Order
where CustomerID = 2
select o).ToList();
35
Part I: Introduction to Project LINQ
By returning a single value or returning values to an array or value list, you can force an immediate
execution of the query, which can be useful when you want the results of the query to be cached.
Likened to SQL Syntax
To help you understand the flow of the LINQ syntax, compare it to standard T-SQL syntax. If you have
written any T-SQL, you know the basic T-SQL query syntax and how it is written.
Pages:
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92