Dela via


Query Expression Syntax for Standard Query Operators

Some of the more frequently used standard query operators have dedicated C# and Visual Basic language keyword syntax that enables them to be called as part of a query expression. A query expression is a different, more readable form of expressing a query than its method-based equivalent. Query expression clauses are translated into calls to the query methods at compile time.

Query Expression Syntax Table

The following table lists the standard query operators that have equivalent query expression clauses. The C# and Visual Basic programming languages do not provide dedicated query expression syntax for the same methods. The table lists the syntax for both of these languages.

Method

C# Query Expression Syntax

Visual Basic Query Expression Syntax

All<TSource>

not applicable

Aggregate … In … Into All(…)

(For more information, see Aggregate Clause (Visual Basic).)

Any

not applicable

Aggregate … In … Into Any()

(For more information, see Aggregate Clause (Visual Basic).)

Average

not applicable

Aggregate … In … Into Average()

(For more information, see Aggregate Clause (Visual Basic).)

Cast<TResult>

Use an explicitly typed range variable, for example:

from int i in numbers

(For more information, see from clause (C# Reference).)

From … As …

(For more information, see From Clause (Visual Basic).)

Count

not applicable

Aggregate … In … Into Count()

(For more information, see Aggregate Clause (Visual Basic).)

Distinct<TSource>(IEnumerable<TSource>)

not applicable

Distinct

(For more information, see Distinct Clause (Visual Basic).)

GroupBy

group … by

-or-

group … by … into …

(For more information, see group clause (C# Reference).)

Group … By … Into …

(For more information, see Group By Clause (Visual Basic).)

GroupJoin<TOuter, TInner, TKey, TResult>(IEnumerable<TOuter>, IEnumerable<TInner>, Func<TOuter, TKey>, Func<TInner, TKey>, Func<TOuter, IEnumerable<TInner>, TResult>)

join … in … on … equals … into …

(For more information, see join clause (C# Reference).)

Group Join … In … On …

(For more information, see Group Join Clause (Visual Basic).)

Join<TOuter, TInner, TKey, TResult>(IEnumerable<TOuter>, IEnumerable<TInner>, Func<TOuter, TKey>, Func<TInner, TKey>, Func<TOuter, TInner, TResult>)

join … in … on … equals …

(For more information, see join clause (C# Reference).)

From x In …, y In … Where x.a = b.a

-or-

Join … [As …]In … On …

(For more information, see Join Clause (Visual Basic).)

LongCount

not applicable

Aggregate … In … Into LongCount()

(For more information, see Aggregate Clause (Visual Basic).)

Max

not applicable

Aggregate … In … Into Max()

(For more information, see Aggregate Clause (Visual Basic).)

Min

not applicable

Aggregate … In … Into Min()

(For more information, see Aggregate Clause (Visual Basic).)

OrderBy<TSource, TKey>(IEnumerable<TSource>, Func<TSource, TKey>)

orderby

(For more information, see orderby clause (C# Reference).)

Order By

(For more information, see Order By Clause (Visual Basic).)

OrderByDescending<TSource, TKey>(IEnumerable<TSource>, Func<TSource, TKey>)

orderby … descending

(For more information, see orderby clause (C# Reference).)

Order By … Descending

(For more information, see Order By Clause (Visual Basic).)

Select

select

(For more information, see select clause (C# Reference).)

Select

(For more information, see Select Clause (Visual Basic).)

SelectMany

Multiple from clauses.

(For more information, see from clause (C# Reference).)

Multiple From clauses

(For more information, see From Clause (Visual Basic).)

Skip<TSource>

not applicable

Skip

(For more information, see Skip Clause (Visual Basic).)

SkipWhile

not applicable

Skip While

(For more information, see Skip While Clause (Visual Basic).)

Sum

not applicable

Aggregate … In … Into Sum()

(For more information, see Aggregate Clause (Visual Basic).)

Take<TSource>

not applicable

Take

(For more information, see Take Clause (Visual Basic).)

TakeWhile

not applicable

Take While

(For more information, see Take While Clause (Visual Basic).)

ThenBy<TSource, TKey>(IOrderedEnumerable<TSource>, Func<TSource, TKey>)

orderby …, …

(For more information, see orderby clause (C# Reference).)

Order By …, …

(For more information, see Order By Clause (Visual Basic).)

ThenByDescending<TSource, TKey>(IOrderedEnumerable<TSource>, Func<TSource, TKey>)

orderby …, … descending

(For more information, see orderby clause (C# Reference).)

Order By …, … Descending

(For more information, see Order By Clause (Visual Basic).)

Where

where

(For more information, see where clause (C# Reference).)

Where

(For more information, see Where Clause (Visual Basic).)

See Also

Reference

Enumerable

Queryable

Concepts

Standard Query Operators Overview

Classification of Standard Query Operators by Manner of Execution