Free mag vol1 | Page 504

CHAPTER 12  LINQ TO OBJECTS Of course, nothing is wrong with these approaches to data manipulation. In fact, you can (and will) certainly make direct use of ADO.NET, the XML namespaces, reflection services, and the various collection types. However, the basic problem is that each of these APIs is an island unto itself, which offers very little in the way of integration. True, it is possible (for example) to save an ADO.NET DataSet as XML, and then manipulate it via the System.Xml namespaces, but nonetheless, data manipulation remains rather asymmetrical. The LINQ API is an attempt to provide a consistent, symmetrical manner in which programmers can obtain and manipulate “data” in the broad sense of the term. Using LINQ, you are able to create directly within the C# programming language constructs called query expressions. These query expressions are based on numerous query operators that have been intentionally designed to look and feel very similar (but not quite identical) to a SQL expression. The twist, however, is that a query expression can be used to interact with numerous types of data— even data that has nothing to do with a relational database. Strictly speaking, “LINQ” is the term used to describe this overall approach to data access. However, based on where you are applying your LINQ queries, you will encounter various terms, such as the following: • LINQ to Objects: This term refers to the act of applying LINQ queries to arrays and collections. • LINQ to XML: This term refers to the act of using LINQ to manipulate and query XML documents. • LINQ to DataSet: This term refers to the act of applying LINQ queries to ADO.NET DataSet objects. • LINQ to Entities: This aspect of LINQ allows you to make use of LINQ queries within the ADO.NET Entity Framework (EF) API. • Parallel LINQ (a.k.a. PLINQ): This allows for parallel processing of data returned from a LINQ query. To be sure, Microsoft seems quite dedicated to integrating LINQ support deeply within the .NET programming environment. Today, LINQ is an integral part of the .NET base class libraries, managed languages, and Visual Studio itself. LINQ Expressions Are Strongly Typed It is also very important to point out that a LINQ query expression (unlike a traditional SQL statement) is strongly typed. Therefore, the C# compiler will keep us honest and make sure that these expressions are syntactically well formed. On a related note, query expressions have metadata representation within the assembly that makes use of them, as the C# LINQ query operators always make a rich underlying object model. Tools such as Visual Studio can use this metadata for useful features such as IntelliSense, autocompletion, and so forth. The Core LINQ Assemblies As mentioned in Chapter 2, the New Project dialog of Visual Studio has the option of selecting which version of the .NET platform you wish to compile against. When you opt to compile against .NET 3.5 or higher, each of the project templates will automatically reference the key LINQ assemblies, which can be viewed using the Solution Explorer. Table 12-2 documents the role of the key LINQ assemblies. However, you will encounter additional LINQ libraries over the remainder of this book. 444