Export (0) Print
Expand All

Query Examples (LINQ to SQL)

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 noteImportant Note:

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 (LINQ to SQL)

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

How to: Return the First Element in a Sequence (LINQ to SQL)

Provides examples of using First.

How to: Return or Skip Elements in a Sequence (LINQ to SQL)

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

How to: Sort Elements in a Sequence (LINQ to SQL)

Provides examples of using OrderBy.

How to: Group Elements in a Sequence (LINQ to SQL)

Provides examples of using GroupBy.

How to: Eliminate Duplicate Elements from a Sequence (LINQ to SQL)

Provides examples of using Distinct.

How to: Determine if Any or All Elements in a Sequence Satisfy a Condition (LINQ to SQL)

Provides examples of using All<TSource> and Any.

How to: Concatenate Two Sequences (LINQ to SQL)

Provides examples of using Concat<TSource>.

How to: Return the Set Difference Between Two Sequences (LINQ to SQL)

Provides examples of using Except.

How to: Return the Set Intersection of Two Sequences (LINQ to SQL)

Provides examples of using Intersect.

How to: Return the Set Union of Two Sequences (LINQ to SQL)

Provides examples of using Union.

How to: Convert a Sequence to an Array (LINQ to SQL)

Provides examples of using ToArray<TSource>.

How to: Convert a Sequence to a Generic List (LINQ to SQL)

Provides examples of using ToList<TSource>.

How to: Convert a Type to a Generic IEnumerable (LINQ to SQL)

Provides examples of using AsEnumerable<TSource>.

How to: Formulate Joins and Cross-Product Queries (LINQ to SQL)

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

How to: Formulate Projections (LINQ to SQL)

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 in LINQ to SQL

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.

Community Additions

ADD
Show:
© 2015 Microsoft