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.

Namespace:   System.Data.Entity.Infrastructure
Assembly:  EntityFramework (in EntityFramework.dll)

NameDescription
System_CAPS_pubmethodSingleAsync()

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

System_CAPS_pubmethodSingleAsync(CancellationToken)

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

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

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

public Task<TElement> SingleAsync()

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 (CancellationToken)

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

public Task<TElement> SingleAsync(
	CancellationToken cancellationToken
)

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.

public Task<TElement> SingleAsync(
	Func<TElement, bool> predicate
)

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.