You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Fix open issues
- Fixes#43760: Update where clause to filter out some values. Update output comment.
- Fixes#43765: Update `let` statement so the query result isn't empty.
- Fixes#43766: Update query parameters so the result set isn't empty.
- Fixes#43768: Add sample data
- Fixes#43790: Audit all samples in this article and ensure all have output.
- Fixes#43809: Update samples to include the data sources.
While doing this, update the project to .NET 9
* Review and update code.
Hide whitespace for this commit. It's mostly formatting changes.
* Edit pass.
Grammar and edit pass.
* Apply suggestions from code review
Co-authored-by: Genevieve Warren <[email protected]>
---------
Co-authored-by: Genevieve Warren <[email protected]>
Copy file name to clipboardExpand all lines: docs/csharp/linq/get-started/query-expression-basics.md
+8-8Lines changed: 8 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: Query expression basics (LINQ)
3
3
description: Introduces concepts related to query expressions
4
-
ms.date: 03/06/2024
4
+
ms.date: 01/16/2025
5
5
---
6
6
# Query expression basics
7
7
@@ -52,7 +52,7 @@ A query expression must begin with a [from](../../language-reference/keywords/fr
52
52
In LINQ, a query variable is any variable that stores a *query* instead of the *results* of a query. More specifically, a query variable is always an enumerable type that produces a sequence of elements when iterated over in a `foreach` statement or a direct call to its <xref:System.Collections.IEnumerator.MoveNext?displayProperty=nameWithType> method.
53
53
54
54
> [!NOTE]
55
-
> Examples in this article uses the following data source and sample data.
55
+
> Examples in this article use the following data source and sample data.
In the previous example, `scoreQuery` is a *query variable,* which is sometimes referred to as just a *query*. The query variable stores no actual result data, which is produced in the `foreach` loop. And when the `foreach` statement executes, the query results aren't returned through the query variable `scoreQuery`. Rather, they're returned through the iteration variable `testScore`. The `scoreQuery` variable can be iterated in a second `foreach` loop. It produces the same results as long as neither it nor the data source has been modified.
65
+
In the previous example, `scoreQuery` is a *query variable,* which is sometimes referred to as just a *query*. The query variable stores no actual result data, which is produced in the `foreach` loop. And when the `foreach` statement executes, the query results aren't returned through the query variable `scoreQuery`. Rather, they're returned through the iteration variable `testScore`. The `scoreQuery` variable can be iterated in a second `foreach` loop. It produces the same results as long as neither it nor the data source was modified.
66
66
67
67
A query variable might store a query that is expressed in query syntax or method syntax, or a combination of the two. In the following examples, both `queryMajorCities` and `queryMajorCities2` are query variables:
68
68
@@ -100,7 +100,7 @@ For more information, see [from clause](../../language-reference/keywords/from-c
100
100
101
101
A query expression must end with either a `group` clause or a `select` clause.
102
102
103
-
#### group clause
103
+
#### The group clause
104
104
105
105
Use the `group` clause to produce a sequence of groups organized by a key that you specify. The key can be any data type. For example, the following query creates a sequence of groups that contains one or more `Country` objects and whose key is a `char` type with value being the first letter of countries' names.
106
106
@@ -134,31 +134,31 @@ For more information, see [into](../../language-reference/keywords/into.md).
134
134
135
135
Between the starting `from` clause, and the ending `select` or `group` clause, all other clauses (`where`, `join`, `orderby`, `from`, `let`) are optional. Any of the optional clauses might be used zero times or multiple times in a query body.
136
136
137
-
#### where clause
137
+
#### The where clause
138
138
139
139
Use the `where` clause to filter out elements from the source data based on one or more predicate expressions. The `where` clause in the following example has one predicate with two conditions.
For more information, see [where clause](../../language-reference/keywords/where-clause.md).
144
144
145
-
#### orderby clause
145
+
#### The orderby clause
146
146
147
147
Use the `orderby` clause to sort the results in either ascending or descending order. You can also specify secondary sort orders. The following example performs a primary sort on the `country` objects by using the `Area` property. It then performs a secondary sort by using the `Population` property.
The `ascending` keyword is optional; it's the default sort order if no order is specified. For more information, see [orderby clause](../../language-reference/keywords/orderby-clause.md).
152
152
153
-
#### join clause
153
+
#### The join clause
154
154
155
155
Use the `join` clause to associate and/or combine elements from one data source with elements from another data source based on an equality comparison between specified keys in each element. In LINQ, join operations are performed on sequences of objects whose elements are different types. After you join two sequences, you must use a `select` or `group` statement to specify which element to store in the output sequence. You can also use an anonymous type to combine properties from each set of associated elements into a new type for the output sequence. The following example associates `prod` objects whose `Category` property matches one of the categories in the `categories` string array. Products whose `Category` doesn't match any string in `categories` are filtered out. The `select` statement projects a new type whose properties are taken from both `cat` and `prod`.
You can also perform a group join by storing the results of the `join` operation into a temporary variable by using the [into](../../language-reference/keywords/into.md) keyword. For more information, see [join clause](../../language-reference/keywords/join-clause.md).
160
160
161
-
#### let clause
161
+
#### The let clause
162
162
163
163
Use the `let` clause to store the result of an expression, such as a method call, in a new range variable. In the following example, the range variable `firstName` stores the first element of the array of strings returned by `Split`.
0 commit comments