Query Examples
.NET Framework 4.5
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.
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. |
In This Section
- 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 and Skip.
- 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 and Any.
- Concatenate Two Sequences
- Provides examples of using Concat.
- 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.
- Convert a Sequence to a Generic List
- Provides examples of using ToList.
- Convert a Type to a Generic IEnumerable
- Provides examples of using AsEnumerable.
- 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.
Related Sections
Copyright © 2012 by Microsoft Corporation. All rights reserved.
Build Date:
Note: