DbRawSqlQuery<TElement>.SingleAsync Method
Asynchronously returns the only element of the query, and throws an exception if there is not exactly one element in the sequence.
Assembly: EntityFramework (in EntityFramework.dll)
Name | Description | |
---|---|---|
![]() | SingleAsync() | Asynchronously returns the only element of the query, and throws an exception if there is not exactly one element in the sequence. |
![]() | SingleAsync(CancellationToken) | Asynchronously returns the only element of the query, and throws an exception if there is not exactly one element in the sequence. |
![]() | SingleAsync(Func<TElement, Boolean>) | Asynchronously returns the only element of the query that satisfies a specified condition, and throws an exception if more than one such element exists. |
![]() | SingleAsync(Func<TElement, Boolean>, CancellationToken) | Asynchronously returns the only element of the query that satisfies a specified condition, and throws an exception if more than one such element exists. |
DbRawSqlQuery<TElement>.SingleAsync Method ()
Asynchronously returns the only element of the query, and throws an exception if there is not exactly one element in the sequence.
Exception | Condition |
---|---|
InvalidOperationException | The query result has more than one element. |
InvalidOperationException | The query result 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.
DbRawSqlQuery<TElement>.SingleAsync Method (CancellationToken)
Asynchronously returns the only element of the query, and throws an exception if there is not exactly one element in the sequence.
Parameters
- cancellationToken
-
Type:
System.Threading.CancellationToken
A CancellationToken to observe while waiting for the task to complete.
Return Value
Type: System.Threading.Tasks.Task<TElement>A task that represents the asynchronous operation. The task result contains the single element of the query result.
Exception | Condition |
---|---|
InvalidOperationException | The query result has more than one element. |
InvalidOperationException | The query result 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.
DbRawSqlQuery<TElement>.SingleAsync Method (Func<TElement, Boolean>)
Asynchronously returns the only element of the query that satisfies a specified condition, and throws an exception if more than one such element exists.
Parameters
- predicate
-
Type:
System.Func<TElement, Boolean>
A function to test each element for a condition.
Return Value
Type: System.Threading.Tasks.Task<TElement>A task that represents the asynchronous operation. The task result contains the single element of the query result that satisfies the condition in predicate.
Exception | Condition |
---|---|
ArgumentNullException | predicate is null . |
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.
DbRawSqlQuery<TElement>.SingleAsync Method (Func<TElement, Boolean>, CancellationToken)
Asynchronously returns the only element of the query that satisfies a specified condition, and throws an exception if more than one such element exists.
public Task<TElement> SingleAsync( Func<TElement, bool> predicate, CancellationToken cancellationToken )
Parameters
- predicate
-
Type:
System.Func<TElement, Boolean>
A function to test each 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<TElement>A task that represents the asynchronous operation. The task result contains the single element of the query result that satisfies the condition in predicate.
Exception | Condition |
---|---|
ArgumentNullException | predicate is null . |
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.