23.3. Query Pieces

This section introduces you to a number of the query operations that make up the basis of LINQ. If you have written SQL statements, these will feel familiar, although the ordering and syntax might take a little time to get used to. There are a number of query operations you can use, and there are numerous reference web sites that provide more information on how to use these. For the moment we will focus on those operations necessary to improve the search query introduced at the beginning of this chapter.

23.3.1. From

Unlike SQL, where the first statement is Select, in LINQ the first statement is typically From. One of the key considerations in the creation of LINQ was providing IntelliSense support within Visual Studio 2008. If you've ever wondered why there is no IntelliSense support in SQL Management Studio for SQL Server 2005 for writing queries, this is because, in order to determine what to select, you need to know where the data is coming from. By reversing the order of the statements, LINQ is able to generate IntelliSense as soon as you start typing.

As you can see from the tooltip in Figure 23-4, the From statement is made up of two parts, <element> and <collection>. The latter is the source collection from which you will be extracting data, and the former is essentially an iteration variable that can be used to refer to the items being queried. This pair can then be repeated for each source collection.

Figure 23.4. Figure 23-4

In this case you can ...

Get Professional Visual Studio® 2008 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.