Επεξεργασία

Κοινή χρήση μέσω


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.

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.

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.

Standard Query Operators Overview (C#)
Explains the concept of standard query operators using C#.

Standard Query Operators Overview (Visual Basic)
Explains the concept of standard query operators using Visual Basic.

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

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