0.
The data can come from an in-memory source, a relational database, or XML, as you saw in the examples
in Chapter 1, ??????Project LINQ.??™??™ If you??™ve worked with SQL syntax, query expressions should look familiar
to you simply because declarative syntax looks very reminiscent of SQL syntax.
From the example in Chapter 1, look at the following highlighted query expression:
DataContext context =
new DataContext("Initial Catalog=AdventureWorks;Integrated Security=sspi");
Table
contact = context.GetTable();
var query =
from c in contact
select new { c.FirstName, c.LastName, c.EmailAddress} ;
21
Part I: Introduction to Project LINQ
Query expressions must follow a specific format for specific reasons. Those reasons are explained in
detail in Chapter 3; for now, suffice it to say that a query expression must begin with a from clause and
end with either a select clause or a groupby clause.
C#
In C#, a query expression is written as follows:
IEnumerable val = from fn in firstnames
where fn.StartsWith("S")
select fn;
In this example, the query expression starts with the from clause informing the query expression where
to retrieve its data.
Pages:
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67