Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions docs/csharp/linq/includes/data-sources-definition.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
author: BillWagner
ms.author: wiwagn
ms.topic: include
ms.date: 10/04/2024
---

> [!NOTE]
> The following examples in this article use the common data sources for this area.
> Each `Student` has a grade level, a primary department, and a series of scores. A `Teacher` also has a `City` property that identifies the campus where the teacher holds classes. A `Department` has a name, and a reference to a `Teacher` who serves as the department head.
> You can find the example data set in the [source repo](https://github.com/dotnet/docs/blob/main/docs/csharp/linq/standard-query-operators/snippets/standard-query-operators/DataSources.cs#L41).

:::code language="csharp" source="../standard-query-operators/snippets/standard-query-operators/DataSources.cs" id="QueryDataSource":::
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@ The conversion methods in this table whose names start with "As" change the stat
|ToList|Converts a collection to a <xref:System.Collections.Generic.List%601>. This method forces query execution.|Not applicable.|<xref:System.Linq.Enumerable.ToList%2A?displayProperty=nameWithType>|
|ToLookup|Puts elements into a <xref:System.Linq.Lookup%602> (a one-to-many dictionary) based on a key selector function. This method forces query execution.|Not applicable.|<xref:System.Linq.Enumerable.ToLookup%2A?displayProperty=nameWithType>|

The following examples in this article use the common data sources for this area:

:::code language="csharp" source="./snippets/standard-query-operators/DataSources.cs" id="QueryDataSource":::

Each `Student` has a grade level, a primary department, and a series of scores. A `Teacher` also has a `City` property that identifies the campus where the teacher holds classes. A `Department` has a name, and a reference to a `Teacher` who serves as the department head.
[!INCLUDE [Datasources](../includes/data-sources-definition.md)]

## Query Expression Syntax Example

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@ The equivalent query using method syntax is shown in the following code:

:::code language="csharp" source="./snippets/standard-query-operators/GroupOverview.cs" id="OverviewSampleMethodSyntax":::

The following examples in this article use the common data sources for this area:

:::code language="csharp" source="./snippets/standard-query-operators/DataSources.cs" id="QueryDataSource":::

Each `Student` has a grade level, a primary department, and a series of scores. A `Teacher` also has a `City` property that identifies the campus where the teacher holds classes. A `Department` has a name, and a reference to a `Teacher` who serves as the department head.
[!INCLUDE [Datasources](../includes/data-sources-definition.md)]

## Group query results

Expand Down
2 changes: 2 additions & 0 deletions docs/csharp/linq/standard-query-operators/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ Where possible, the queries in this section use a sequence of words or numbers a

Each `Student` has a grade level, a primary department, and a series of scores. A `Teacher` also has a `City` property that identifies the campus where the teacher holds classes. A `Department` has a name, and a reference to a `Teacher` who serves as the department head.

You can find the data set in the [source repo](https://github.com/dotnet/docs/blob/main/docs/csharp/linq/standard-query-operators/snippets/standard-query-operators/DataSources.cs#L41).

## Types of query operators

The standard query operators differ in the timing of their execution, depending on whether they return a singleton value or a sequence of values. Those methods that return a singleton value (such as <xref:System.Linq.Enumerable.Average%2A> and <xref:System.Linq.Enumerable.Sum%2A>) execute immediately. Methods that return a sequence defer the query execution and return an enumerable object. You can use the output sequence of one query as the input sequence to another query. Calls to query methods can be chained together in one query, which enables queries to become arbitrarily complex.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ The following illustration shows a conceptual view of two sets and the elements
|Join|Joins two sequences based on key selector functions and extracts pairs of values.|`join … in … on … equals …`|<xref:System.Linq.Enumerable.Join%2A?displayProperty=nameWithType><br /><br /> <xref:System.Linq.Queryable.Join%2A?displayProperty=nameWithType>|
|GroupJoin|Joins two sequences based on key selector functions and groups the resulting matches for each element.|`join … in … on … equals … into …`|<xref:System.Linq.Enumerable.GroupJoin%2A?displayProperty=nameWithType><br /><br /> <xref:System.Linq.Queryable.GroupJoin%2A?displayProperty=nameWithType>|

The following examples in this article use the common data sources for this area:

:::code language="csharp" source="./snippets/standard-query-operators/DataSources.cs" id="QueryDataSource":::

Each `Student` has a grade level, a primary department, and a series of scores. A `Teacher` also has a `City` property that identifies the campus where the teacher holds classes. A `Department` has a name, and a reference to a `Teacher` who serves as the department head.
[!INCLUDE [Datasources](../includes/data-sources-definition.md)]

The following example uses the `join … in … on … equals …` clause to join two sequences based on specific value:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,7 @@ The following example depicts the behavior of <xref:System.Linq.Enumerable.Excep

:::image type="content" source="./media/set-operations/except-behavior-graphic.png" alt-text="Graphic showing the action of Except()":::

The following examples in this article use the common data sources for this area:

:::code language="csharp" source="./snippets/standard-query-operators/DataSources.cs" id="QueryDataSource":::

Each `Student` has a grade level, a primary department, and a series of scores. A `Teacher` also has a `City` property that identifies the campus where the teacher holds classes. A `Department` has a name, and a reference to a `Teacher` who serves as the department head.
[!INCLUDE [Datasources](../includes/data-sources-definition.md)]

:::code language="csharp" source="./snippets/standard-query-operators/SetOperations.cs" id="Except":::

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class Teacher
public required int ID { get; init; }
public required string City { get; init; }
}

public class Department
{
public required string Name { get; init; }
Expand Down
6 changes: 1 addition & 5 deletions docs/csharp/linq/standard-query-operators/sorting-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ The standard query operator methods that sort data are listed in the following s
|ThenByDescending|Performs a secondary sort in descending order.|`orderby …, … descending`|<xref:System.Linq.Enumerable.ThenByDescending%2A?displayProperty=nameWithType><br /><br /> <xref:System.Linq.Queryable.ThenByDescending%2A?displayProperty=nameWithType>|
|Reverse|Reverses the order of the elements in a collection.|Not applicable.|<xref:System.Linq.Enumerable.Reverse%2A?displayProperty=nameWithType><br /><br /> <xref:System.Linq.Queryable.Reverse%2A?displayProperty=nameWithType>|

The following examples in this article use the common data sources for this area:

:::code language="csharp" source="./snippets/standard-query-operators/DataSources.cs" id="QueryDataSource":::

Each `Student` has a grade level, a primary department, and a series of scores. A `Teacher` also has a `City` property that identifies the campus where the teacher holds classes. A `Department` has a name, and a reference to a `Teacher` who serves as the department head.
[!INCLUDE [Datasources](../includes/data-sources-definition.md)]

## Primary Ascending Sort

Expand Down