Chapter 10

Working with Language Integrated Query (LINQ)

What You Will Learn in this Chapter

  • Understanding query expressions
  • Understanding method-based LINQ queries
  • Utilizing LINQ to XML


You can find the code downloads for this chapter at on the Download Code tab. The code is in the chapter10 download and individually named according to the names throughout the chapter.

Language Integrated Query (LINQ) is a language feature in the .NET Framework that enables you to use common syntax to query data in a collection, an XML document, a database, or any type that supports the IEnumerable<T> or IQueryable<T> interface. Prior to LINQ, a developer needed to learn different syntax depending on the source of the data. If the source were a database, you needed to learn SQL. If the source were an XML document, you needed to learn XQuery. If the source were an array or a collection, you would write a looping structure, such as a foreach loop, that would enumerate through the items in the collection and filter them appropriately. LINQ enables you to use common syntax regardless of what the source is.

In this chapter, you learn two different styles of syntax for LINQ. Query expressions are the first style, and method-based queries are the second. They are functionally equivalent, which can sometimes be confusing when you first learn LINQ because you can write the code two different ways and it does the exact ...

Get MCSD Certification Toolkit (Exam 70-483): Programming in C# now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.