DbRawSqlQuery<TElement>.SingleOrDefaultAsync Method
Asynchronously returns the only element of a sequence, or a default value if the sequence is empty; this method throws an exception if there is more than one element in the sequence.
Assembly: EntityFramework (in EntityFramework.dll)
Name | Description | |
---|---|---|
![]() | SingleOrDefaultAsync() | Asynchronously returns the only element of a sequence, or a default value if the sequence is empty; this method throws an exception if there is more than one element in the sequence. |
![]() | SingleOrDefaultAsync(CancellationToken) | Asynchronously returns the only element of a sequence, or a default value if the sequence is empty; this method throws an exception if there is more than one element in the sequence. |
![]() | SingleOrDefaultAsync(Func<TElement, Boolean>) | Asynchronously returns the only element of the query that satisfies a specified condition or a default value if no such element exists; this method throws an exception if more than one element satisfies the condition. |
![]() | SingleOrDefaultAsync(Func<TElement, Boolean>, CancellationToken) | Asynchronously returns the only element of the query that satisfies a specified condition or a default value if no such element exists; this method throws an exception if more than one element satisfies the condition. |
DbRawSqlQuery<TElement>.SingleOrDefaultAsync Method ()
Asynchronously returns the only element of a sequence, or a default value if the sequence is empty; this method throws an exception if there is more than one element in the sequence.
Exception | Condition |
---|---|
InvalidOperationException | The query result has more than one element. |
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>.SingleOrDefaultAsync Method (CancellationToken)
Asynchronously returns the only element of a sequence, or a default value if the sequence is empty; this method throws an exception if there is more than 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, or default ( TElement ) if the sequence contains no elements.
Exception | Condition |
---|---|
InvalidOperationException | The query result has more than one element. |
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>.SingleOrDefaultAsync Method (Func<TElement, Boolean>)
Asynchronously returns the only element of the query that satisfies a specified condition or a default value if no such element exists; this method throws an exception if more than one element satisfies the condition.
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, or default ( TElement ) if no such element is found.
Exception | Condition |
---|---|
ArgumentNullException | predicate is null . |
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>.SingleOrDefaultAsync Method (Func<TElement, Boolean>, CancellationToken)
Asynchronously returns the only element of the query that satisfies a specified condition or a default value if no such element exists; this method throws an exception if more than one element satisfies the condition.
public Task<TElement> SingleOrDefaultAsync( 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, or default ( TElement ) if no such element is found.
Exception | Condition |
---|---|
ArgumentNullException | predicate is null . |
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.