Data Access has been discontinued. Please refer to this page for more information.

Standard LINQ Query Operators

In a query, you specify the information that you want to retrieve from the data source. A query can also specify how that information should be sorted, grouped, and shaped before it is returned. LINQ provides a set of standard query methods that you can use in a query. Most of these methods operate on sequences; in this context, a sequence is an object which type implements the IEnumerable interface or the IQueryable interface. The standard query operators query functionality includes filtering, projection, aggregation, sorting, grouping, paging, and more. Some of the more frequently used standard query operators have dedicated keyword syntax so that they can be called by using query expression syntax.

Projection and Filtering Methods

Projection refers to transforming the elements of a result set into a desired form. For example, you can project a subset of the properties you need from each object in the result set, you can project a property and perform a mathematical calculation on it, or you can project the entire object from the result set. The projection methods are Select and SelectMany.

Filtering refers to the operation of restricting the result set to contain only those elements that match a specified condition. The filtering method is Where.

Join Methods

Joining is an important operation in queries that target data sources that have no navigable relationships to each other. A join of two data sources is the association of objects in one data source with objects in the other data source that share a common attribute or property. The join methods are Join and GroupJoin.

Set Methods

Set operations in LINQ are query operations that base their result sets on the presence or absence of equivalent elements within the same or in another collection (or set). The set methods are All, Any, Concat, Contains, DefaultIfEmpty, Distinct, Except, Intersect, and Union.

Ordering Methods

Ordering, or sorting, refers to the ordering of the elements of a result set based on one or more attributes. By specifying more than one sort criterion, you can break ties within a group.

Most overloads of the ordering methods are supported, except for those which use an IComparer. This is because the comparer cannot be translated to the data source. The ordering methods are OrderBy, OrderByDescending, Descending, and Reverse.

Grouping Methods

Grouping refers to placing data into groups so that the elements in each group share a common attribute. The grouping method is GroupBy.

Aggregate Methods

An aggregation operation computes a single value from a collection of values. For example, calculating the average daily temperature from a month's worth of daily temperature values is an aggregation operation. The aggregate methods are Aggregate, Average, Count, LongCount, Max, Min, and Sum.

Paging Methods

Paging operations return a single, specific element from a sequence. The element methods are ElementAt, First, FirstOrDefault, Last, LastOrDefault, Single, Skip, Take, TakeWhile.

See Also