concept LINQ query in category .net

appears as: LINQ queries, LINQ query, A LINQ query, The LINQ query
LINQ in Action

This is an excerpt from Manning's book LINQ in Action.

In chapter 2, we’ll show you the details of how the programming languages have been extended to support LINQ. In chapter 3, you’ll learn how to write LINQ queries. This is where you’ll learn about query operators, query expressions, and expression trees. But you still have a few things to discover before getting there.

Figure 3.2. A LINQ query represented as a factory where query operators are machines and sequences are the material.

It’s interesting to note how the Authors property is initialized with a nested query. This is possible thanks to query compositionality. LINQ queries are fully compositional, meaning that queries can be arbitrarily nested. The result of the subquery is automatically transformed into a collection of type IEnumerable<Author>.

This technique may not seem very advanced, but it’s good to remember that it’s possible and provide an example to demonstrate how to use it. Such small tricks are useful when using LINQ queries.