DbRawSqlQuery<TElement>.SingleAsync Method

Definition

Overloads

SingleAsync()

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(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>, 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.

SingleAsync()

Asynchronously returns the only element of the query, and throws an exception if there is not exactly one element in the sequence.

public System.Threading.Tasks.Task<TElement> SingleAsync ();
member this.SingleAsync : unit -> System.Threading.Tasks.Task<'Element>
Public Function SingleAsync () As Task(Of TElement)

Returns

Task<TElement>

A task that represents the asynchronous operation. The task result contains the single element of the query result.

Exceptions

The query result is empty.

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

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.

public System.Threading.Tasks.Task<TElement> SingleAsync (Func<TElement,bool> predicate);
member this.SingleAsync : Func<'Element, bool> -> System.Threading.Tasks.Task<'Element>
Public Function SingleAsync (predicate As Func(Of TElement, Boolean)) As Task(Of TElement)

Parameters

predicate
Func<TElement,Boolean>

A function to test each element for a condition.

Returns

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.

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

SingleAsync(CancellationToken)

Asynchronously returns the only element of the query, and throws an exception if there is not exactly one element in the sequence.

public System.Threading.Tasks.Task<TElement> SingleAsync (System.Threading.CancellationToken cancellationToken);
member this.SingleAsync : System.Threading.CancellationToken -> System.Threading.Tasks.Task<'Element>

Parameters

cancellationToken
CancellationToken

A CancellationToken to observe while waiting for the task to complete.

Returns

Task<TElement>

A task that represents the asynchronous operation. The task result contains the single element of the query result.

Exceptions

The query result is empty.

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

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.

public System.Threading.Tasks.Task<TElement> SingleAsync (Func<TElement,bool> predicate, System.Threading.CancellationToken cancellationToken);
member this.SingleAsync : Func<'Element, bool> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<'Element>

Parameters

predicate
Func<TElement,Boolean>

A function to test each element for a condition.

cancellationToken
CancellationToken

A CancellationToken to observe while waiting for the task to complete.

Returns

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.

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