Chapter 3. The LINQ Architecture


In scanning the examples in the previous section, you probably noticed use of the var keyword, as well as the use of the new keyword without an accompanying class name. What you see are two new features of C# 3.0, namely type inference and anonymous types, added to the language in support of LINQ. Additional language features include query expressions, lambda expressions, expression trees, extension methods, and object initializers, all of which will be explained in the following sections.

Figure 3-1. LINQ_Architecture


LINQ's architecture is designed around a high-level, collection-like abstraction. This means that LINQ queries are written in C# 3.0 against the notion of an object collection, and then translated by the compiler into IL for execution against a particular data source (see Figure 1). This provides many benefits, including:

  • Ability to target different data sources, e.g. databases and XML documents.

  • Ability to use LINQ with existing .NET 1.* and 2.0 objects.

  • Ability to extend LINQ to support new classes and technologies.

As an analogy, consider the foreach loop. The foreach is merely syntactic sugar for a while loop written against the IEnumerable and IEnumerator interfaces. However, foreach represents a convenient and powerful abstraction, allowing intuitive iteration across different types of collections, today and in the future. It's now hard to imagine C# or VB without foreach.



LINQ[c] The Future of Data Access in C# 3. 0
LINQ[c] The Future of Data Access in C# 3. 0
ISBN: N/A
EAN: N/A
Year: 2006
Pages: 25

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net