Chapter 9. Querying with LINQ

.NET 3.5 introduces a new technology called Language Integrated Query, or LINQ (pronounced "link"). LINQ is designed to fill the gap that exists between traditional .NET languages, which offer strong typing and full object-oriented development, and query languages such as SQL, with syntax specifically designed for query operations. With the introduction of LINQ into .NET, query becomes a first class concept in .NET, whether object, XML, or data queries.

LINQ includes three basic types of queries, LINQ to Objects, LINQ to XML (or XLINQ), and LINQ to SQL (or DLINQ). Each type of query offers specific capabilities and is designed to query a specific source.

In this chapter, we look at all three flavors of LINQ, and how each enables you to simplify query operations. We also look at some new language features of the .NET CLR that you will use to create LINQ queries, as well as the tooling support added to Visual Studio to support using LINQ.

LINQ to Objects

The first and most basic flavor of LINQ is LINQ to Objects. LINQ to Objects enables you to perform complex query operations against any enumerable object (any object that implements the IEnumerable interface). While the notion of creating enumerable objects that can be queried or sorted is not new to .NET, doing this in versions prior to version 3.5 usually required a significant amount of code. Often that code would end up being so complex that it would be hard for other developers to read and understand, ...

Get Professional ASP.NET 3.5 SP1 Edition: In C# and VB now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.