Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 3.4k
Added ToHashSetAsync<T> Extension methods on IQueryable<T>#32905
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
82 changes: 80 additions & 2 deletions
82 src/EFCore/Extensions/EntityFrameworkQueryableExtensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -2337,6 +2337,84 @@ public static async Task<TSource[]> ToArrayAsync<TSource>( | ||
| #endregion | ||
| #region ToHashSet | ||
| /// <summary> | ||
| /// Asynchronously creates a <see cref="HashSet{T}" /> from an <see cref="IQueryable{T}" /> by enumerating it | ||
| /// asynchronously. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// <para> | ||
| /// Multiple active operations on the same context instance are not supported. Use <see langword="await" /> to ensure | ||
| /// that any asynchronous operations have completed before calling another method on this context. | ||
| /// See <see href="https://aka.ms/efcore-docs-threading">Avoiding DbContext threading issues</see> for more information and examples. | ||
| /// </para> | ||
| /// <para> | ||
| /// See <see href="https://aka.ms/efcore-docs-async-linq">Querying data with EF Core</see> for more information and examples. | ||
| /// </para> | ||
| /// </remarks> | ||
| /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam> | ||
| /// <param name="source">An <see cref="IQueryable{T}" /> to create a set from.</param> | ||
| /// <param name="cancellationToken">A <see cref="CancellationToken" /> to observe while waiting for the task to complete.</param> | ||
| /// <returns> | ||
| /// A task that represents the asynchronous operation. | ||
| /// The task result contains a <see cref="HashSet{T}" /> that contains elements from the input sequence. | ||
| /// </returns> | ||
| /// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception> | ||
| /// <exception cref="OperationCanceledException">If the <see cref="CancellationToken" /> is canceled.</exception> | ||
| public static async Task<HashSet<TSource>> ToHashSetAsync<TSource>( | ||
| this IQueryable<TSource> source, | ||
| CancellationToken cancellationToken = default) | ||
| { | ||
| var set = new HashSet<TSource>(); | ||
| await foreach (var element in source.AsAsyncEnumerable().WithCancellation(cancellationToken).ConfigureAwait(false)) | ||
| { | ||
| set.Add(element); | ||
| } | ||
| return set; | ||
| } | ||
| /// <summary> | ||
| /// Asynchronously creates a <see cref="HashSet{T}" /> from an <see cref="IQueryable{T}" /> by enumerating it | ||
| /// asynchronously. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// <para> | ||
| /// Multiple active operations on the same context instance are not supported. Use <see langword="await" /> to ensure | ||
| /// that any asynchronous operations have completed before calling another method on this context. | ||
| /// See <see href="https://aka.ms/efcore-docs-threading">Avoiding DbContext threading issues</see> for more information and examples. | ||
| /// </para> | ||
| /// <para> | ||
| /// See <see href="https://aka.ms/efcore-docs-async-linq">Querying data with EF Core</see> for more information and examples. | ||
| /// </para> | ||
| /// </remarks> | ||
| /// <typeparam name="TSource">The type of the elements of <paramref name="source" />.</typeparam> | ||
| /// <param name="source">An <see cref="IQueryable{T}" /> to create a set from.</param> | ||
| /// <param name="comparer">The <see cref="IEqualityComparer{T}"/> implementation to use when comparing values in the set, or null to use the default <see cref="EqualityComparer{T}"/> implementation for the set type.</param> | ||
| /// <param name="cancellationToken">A <see cref="CancellationToken" /> to observe while waiting for the task to complete.</param> | ||
| /// <returns> | ||
| /// A task that represents the asynchronous operation. | ||
| /// The task result contains a <see cref="HashSet{T}" /> that contains elements from the input sequence. | ||
| /// </returns> | ||
| /// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception> | ||
| /// <exception cref="OperationCanceledException">If the <see cref="CancellationToken" /> is canceled.</exception> | ||
| public static async Task<HashSet<TSource>> ToHashSetAsync<TSource>( | ||
| this IQueryable<TSource> source, | ||
| IEqualityComparer<TSource>? comparer, | ||
| CancellationToken cancellationToken = default) | ||
| { | ||
| var set = new HashSet<TSource>(comparer); | ||
| await foreach (var element in source.AsAsyncEnumerable().WithCancellation(cancellationToken).ConfigureAwait(false)) | ||
ajcvickers marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| { | ||
| set.Add(element); | ||
| } | ||
| return set; | ||
| } | ||
| #endregion | ||
| #region Include | ||
| internal static readonly MethodInfo IncludeMethodInfo | ||
| @@ -2834,8 +2912,8 @@ source.Provider is EntityQueryProvider | ||
| /// </exception> | ||
| public static IQueryable<T> TagWithCallSite<T>( | ||
| this IQueryable<T> source, | ||
| [NotParameterized][CallerFilePath] string? filePath = null, | ||
| [NotParameterized][CallerLineNumber] int lineNumber = 0) | ||
| [NotParameterized][CallerFilePath] string? filePath = null, | ||
| [NotParameterized][CallerLineNumber] int lineNumber = 0) | ||
| => source.Provider is EntityQueryProvider | ||
| ? source.Provider.CreateQuery<T>( | ||
| Expression.Call( | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.