DbRawSqlQuery<TElement>.SingleOrDefaultAsync Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
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. |
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() |
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.
public System.Threading.Tasks.Task<TElement> SingleOrDefaultAsync (Func<TElement,bool> predicate, System.Threading.CancellationToken cancellationToken);
member this.SingleOrDefaultAsync : Func<'Element, bool> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<'Element>
Parameters
- cancellationToken
- CancellationToken
A CancellationToken to observe while waiting for the task to complete.
Returns
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.
Exceptions
predicate
is
null
.
More than one element satisfies the condition in
predicate
.
Remarks
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.
Applies to
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.
public System.Threading.Tasks.Task<TElement> SingleOrDefaultAsync (System.Threading.CancellationToken cancellationToken);
member this.SingleOrDefaultAsync : System.Threading.CancellationToken -> System.Threading.Tasks.Task<'Element>
Parameters
- cancellationToken
- CancellationToken
A CancellationToken to observe while waiting for the task to complete.
Returns
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.
Exceptions
The query result has more than one element.
Remarks
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.
Applies to
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.
public System.Threading.Tasks.Task<TElement> SingleOrDefaultAsync ();
member this.SingleOrDefaultAsync : unit -> System.Threading.Tasks.Task<'Element>
Public Function SingleOrDefaultAsync () As Task(Of TElement)
Returns
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.
Exceptions
The query result has more than one element.
Remarks
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.
Applies to
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.
public System.Threading.Tasks.Task<TElement> SingleOrDefaultAsync (Func<TElement,bool> predicate);
member this.SingleOrDefaultAsync : Func<'Element, bool> -> System.Threading.Tasks.Task<'Element>
Public Function SingleOrDefaultAsync (predicate As Func(Of TElement, Boolean)) As Task(Of TElement)
Parameters
Returns
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.
Exceptions
predicate
is
null
.
More than one element satisfies the condition in
predicate
.
Remarks
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.
Applies to
Entity Framework