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
Copy file name to clipboardExpand all lines: sdk/core/Azure.Core/samples/Response.md
+43Lines changed: 43 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -127,6 +127,49 @@ await foreach (Page<SecretProperties> page in allSecretProperties.AsPages())
127
127
}
128
128
```
129
129
130
+
## Using System.Linq.Async with AsyncPageable
131
+
132
+
The [`System.Linq.Async`](https://www.nuget.org/packages/System.Linq.Async) package provides a set of LINQ methods that operate on `IAsyncEnumerable<T>` type.
133
+
Because `AsyncPageable<T>` implements `IAsyncEnumerable<T>` you can use `System.Linq.Async` to easily query and transform the data.
134
+
135
+
### Convert to a `List<T>`
136
+
137
+
`ToListAsync` can be used to convert an `AsyncPageable` to a `List<T>`. This might make several service calls if the data isn't returned in a single page.
`Take` can be used to get only the first `N` elements of the `AsyncPageable`. Using `Take` will make the fewest service calls required to get `N` items.
`System.Linq.Async` provides other useful methods like `Select`, `Where`, `OrderBy`, `GroupBy`, etc. that provide functionality equivalent to their synchronous [`Enumerable` counterparts](https://docs.microsoft.com/dotnet/api/system.linq.enumerable).
163
+
164
+
### Beware client-side evaluation
165
+
166
+
`System.Linq.Async` LINQ operations are executed on the client so the following query would fetch all the items just to count them:
167
+
168
+
```C# Snippet:SystemLinqAsyncCount
169
+
// DANGER! DO NOT COPY: CountAsync as used here fetches all the secrets locally to count them.
0 commit comments