QueryableExtensions::SingleAsync Method
Asynchronously returns the only element of a sequence, and throws an exception if there is not exactly one element in the sequence.
Assembly: EntityFramework (in EntityFramework.dll)
| Name | Description | |
|---|---|---|
![]() ![]() | SingleAsync<TSource>(IQueryable<TSource>^) | Asynchronously returns the only element of a sequence, and throws an exception if there is not exactly one element in the sequence. |
![]() ![]() | SingleAsync<TSource>(IQueryable<TSource>^, CancellationToken) | Asynchronously returns the only element of a sequence, and throws an exception if there is not exactly one element in the sequence. |
![]() ![]() | SingleAsync<TSource>(IQueryable<TSource>^, Expression<Func<TSource, Boolean>^>^) | Asynchronously returns the only element of a sequence that satisfies a specified condition, and throws an exception if more than one such element exists. |
![]() ![]() | SingleAsync<TSource>(IQueryable<TSource>^, Expression<Func<TSource, Boolean>^>^, CancellationToken) | Asynchronously returns the only element of a sequence that satisfies a specified condition, and throws an exception if more than one such element exists. |
QueryableExtensions::SingleAsync<TSource> Method (IQueryable<TSource>^)
Asynchronously returns the only element of a sequence, and throws an exception if there is not exactly one element in the sequence.
public: generic<typename TSource> [ExtensionAttribute] static Task<TSource>^ SingleAsync( IQueryable<TSource>^ source )
Parameters
- source
-
Type:
System.Linq::IQueryable<TSource>^
An IQueryable<T> to return the single element of.
Return Value
Type: System.Threading.Tasks::Task<TSource>^A task that represents the asynchronous operation. The task result contains the single element of the input sequence.
Type Parameters
- TSource
The type of the elements of source.
| Exception | Condition |
|---|---|
| ArgumentNullException | source is null . |
| InvalidOperationException | source does not implement IDbAsyncQueryProvider . |
| InvalidOperationException | The source sequence is empty. |
Multiple active operations on the same context instance are not supported. Use 'await' to ensure that any asynchronous operations have completed before calling another method on this context.
QueryableExtensions::SingleAsync<TSource> Method (IQueryable<TSource>^, CancellationToken)
Asynchronously returns the only element of a sequence, and throws an exception if there is not exactly one element in the sequence.
public: generic<typename TSource> [ExtensionAttribute] static Task<TSource>^ SingleAsync( IQueryable<TSource>^ source, CancellationToken cancellationToken )
Parameters
- source
-
Type:
System.Linq::IQueryable<TSource>^
An IQueryable<T> to return the single element of.
- cancellationToken
-
Type:
System.Threading::CancellationToken
A CancellationToken to observe while waiting for the task to complete.
Return Value
Type: System.Threading.Tasks::Task<TSource>^A task that represents the asynchronous operation. The task result contains the single element of the input sequence.
Type Parameters
- TSource
The type of the elements of source.
| Exception | Condition |
|---|---|
| ArgumentNullException | source is null . |
| InvalidOperationException | source does not implement IDbAsyncQueryProvider . |
| InvalidOperationException | source has more than one element. |
| InvalidOperationException | The source sequence is empty. |
Multiple active operations on the same context instance are not supported. Use 'await' to ensure that any asynchronous operations have completed before calling another method on this context.
QueryableExtensions::SingleAsync<TSource> Method (IQueryable<TSource>^, Expression<Func<TSource, Boolean>^>^)
Asynchronously returns the only element of a sequence that satisfies a specified condition, and throws an exception if more than one such element exists.
public: generic<typename TSource> [SuppressMessageAttribute("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")] [ExtensionAttribute] static Task<TSource>^ SingleAsync( IQueryable<TSource>^ source, Expression<Func<TSource, bool>^>^ predicate )
Parameters
- source
-
Type:
System.Linq::IQueryable<TSource>^
An IQueryable<T> to return the the single element of.
- predicate
-
Type:
System.Linq.Expressions::Expression<Func<TSource, Boolean>^>^
A function to test an element for a condition.
Return Value
Type: System.Threading.Tasks::Task<TSource>^A task that represents the asynchronous operation. The task result contains the single element of the input sequence that satisfies the condition in predicate.
Type Parameters
- TSource
The type of the elements of source.
| Exception | Condition |
|---|---|
| ArgumentNullException | source or predicate is null . |
| InvalidOperationException | source does not implement IDbAsyncQueryProvider . |
| InvalidOperationException | No element satisfies the condition in predicate . |
| InvalidOperationException | More than one element satisfies the condition in predicate . |
Multiple active operations on the same context instance are not supported. Use 'await' to ensure that any asynchronous operations have completed before calling another method on this context.
QueryableExtensions::SingleAsync<TSource> Method (IQueryable<TSource>^, Expression<Func<TSource, Boolean>^>^, CancellationToken)
Asynchronously returns the only element of a sequence that satisfies a specified condition, and throws an exception if more than one such element exists.
public: generic<typename TSource> [SuppressMessageAttribute("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")] [SuppressMessageAttribute("Microsoft.Design", "CA1006:DoNotNestGenericTypesInMemberSignatures")] [ExtensionAttribute] static Task<TSource>^ SingleAsync( IQueryable<TSource>^ source, Expression<Func<TSource, bool>^>^ predicate, CancellationToken cancellationToken )
Parameters
- source
-
Type:
System.Linq::IQueryable<TSource>^
An IQueryable<T> to return the single element of.
- predicate
-
Type:
System.Linq.Expressions::Expression<Func<TSource, Boolean>^>^
A function to test an element for a condition.
- cancellationToken
-
Type:
System.Threading::CancellationToken
A CancellationToken to observe while waiting for the task to complete.
Return Value
Type: System.Threading.Tasks::Task<TSource>^A task that represents the asynchronous operation. The task result contains the single element of the input sequence that satisfies the condition in predicate.
Type Parameters
- TSource
The type of the elements of source.
| Exception | Condition |
|---|---|
| ArgumentNullException | source or predicate is null . |
| InvalidOperationException | source does not implement IDbAsyncQueryProvider . |
| InvalidOperationException | No element satisfies the condition in predicate . |
| InvalidOperationException | More than one element satisfies the condition in predicate . |
Multiple active operations on the same context instance are not supported. Use 'await' to ensure that any asynchronous operations have completed before calling another method on this context.

