Skip to Content
Beginning ASP.NET 3.5: In C# and VB
book

Beginning ASP.NET 3.5: In C# and VB

by Imar Spaanjaars
March 2008
Intermediate to advanced content levelIntermediate to advanced
766 pages
21h 15m
English
Wrox
Content preview from Beginning ASP.NET 3.5: In C# and VB

13.3. Introducing Query Syntax

The query you saw in the previous example is quite simple; it requests all the authorized reviews from the system and returns them in a sorted order. However, the querying capabilities of LINQ are much more powerful than this. In this section you learn more about the LINQ query syntax that you use to query your object model.

13.3.1. Standard Query Operators

LINQ supports a large number of query operators — keywords that allow you to select, order, or filter data that is to be returned from the query. Although all of the examples in this chapter are discussed in the context of LINQ to SQL, you can easily apply them to the other LINQ implementations as well. In the following section you get an overview of the most important standard query operators followed by an example. Each of the examples uses the object model and the DataContext object called myDataContext you created earlier as the data source to query against.

13.3.1.1. Select

The Select keyword (select in C#) is used to retrieve objects from the source you are querying. In this example you see how to select an object of an existing type. Later in this chapter you see how to define new object shapes on the fly.

VB.NET

Dim allReviews = From r In myDataContext.Reviews _
                 Select r

C#

var allReviews = from r in myDataContext.Reviews
                 select r;

The r variable in this example is referred to as a range variable that is only available within the current query. You typically introduce the range variable ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Beginning ASP.NET 4: in C# and VB

Beginning ASP.NET 4: in C# and VB

Imar Spaanjaars
Professional ASP.NET 3.5 SP1 Edition: In C# and VB

Professional ASP.NET 3.5 SP1 Edition: In C# and VB

Bill Evjen, Scott Hanselman, Devin Rader

Publisher Resources

ISBN: 9780470187593Purchase book