Skip to content

Commit

Permalink
include a link to the data set within LINQ examples
Browse files Browse the repository at this point in the history
  • Loading branch information
timdeschryver committed Oct 4, 2024
1 parent a512438 commit 108265f
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 28 deletions.
14 changes: 14 additions & 0 deletions docs/csharp/linq/includes/data-sources-definition.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
author: BillWagner
ms.author: wiwagn
ms.topic: include
ms.date: 10/04/2024
---

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

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

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).
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
6 changes: 1 addition & 5 deletions docs/csharp/linq/standard-query-operators/grouping-data.md
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
4 changes: 3 additions & 1 deletion docs/csharp/linq/standard-query-operators/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ The following code example demonstrates how the standard query operators can be

Where possible, the queries in this section use a sequence of words or numbers as the input source. For queries where more complicated relationships between objects are used, the following sources that model a school are used:

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

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
6 changes: 1 addition & 5 deletions docs/csharp/linq/standard-query-operators/join-operations.md
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
6 changes: 1 addition & 5 deletions docs/csharp/linq/standard-query-operators/set-operations.md
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
@@ -1,6 +1,6 @@
namespace StandardQueryOperators;

//<QueryDataSource>
//<QueryDataSourceModels>
public enum GradeLevel
{
FirstYear = 1,
Expand Down Expand Up @@ -28,15 +28,17 @@ public class Teacher
public required int ID { get; init; }
public required string City { get; init; }
}

public class Department
{
public required string Name { get; init; }
public int ID { get; init; }

public required int TeacherID { get; init; }
}
// </QueryDataSource>
// </QueryDataSourceModels>

//<QueryDataSource>
public static class Sources
{
public static IEnumerable<Department> Departments =>
Expand Down Expand Up @@ -132,3 +134,4 @@ public static class Sources
new() { First = "Noel", Last = "Svensson", ID = 973, City = "Seattle" }
];
}
// </QueryDataSource>
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

0 comments on commit 108265f

Please sign in to comment.