Export (0) Print
Expand All

Query Examples

This section provides Visual Basic and C# examples of typical LINQ to SQL queries. Developers using Visual Studio can find many more examples in a sample solution available in the Samples section. For more information, see Samples [LINQ to SQL].

Important note Important

db is often used in code examples in LINQ to SQL documentation. db is assumed to be an instance of a Northwind class, which inherits from DataContext.

Aggregate Queries

Describes how to use Average, Count, and so forth.

Return the First Element in a Sequence

Provides examples of using First.

Return Or Skip Elements in a Sequence

Provides examples of using Take<TSource> and Skip<TSource>.

Sort Elements in a Sequence

Provides examples of using OrderBy.

Group Elements in a Sequence

Provides examples of using GroupBy.

Eliminate Duplicate Elements from a Sequence

Provides examples of using Distinct.

Determine if Any or All Elements in a Sequence Satisfy a Condition

Provides examples of using All<TSource> and Any.

Concatenate Two Sequences

Provides examples of using Concat<TSource>.

Return the Set Difference Between Two Sequences

Provides examples of using Except.

Return the Set Intersection of Two Sequences

Provides examples of using Intersect.

Return the Set Union of Two Sequences

Provides examples of using Union.

Convert a Sequence to an Array

Provides examples of using ToArray<TSource>.

Convert a Sequence to a Generic List

Provides examples of using ToList<TSource>.

Convert a Type to a Generic IEnumerable

Provides examples of using AsEnumerable<TSource>.

Formulate Joins and Cross-Product Queries

Provides examples of using foreign-key navigation in the from, where, and select clauses.

Formulate Projections

Provides examples of combining select with other features (for example, anonymous types) to form query projections.

Standard Query Operators Overview

Explains the concept of standard query operators.

Query Concepts

Explains how LINQ to SQL uses concepts that apply to queries.

Programming Guide [LINQ to SQL]

Provides a portal to topics that explain programming concepts related to LINQ to SQL.

Show:
© 2015 Microsoft