EntityFrameworkQueryableExtensions.SingleAsync Method

Definition

Overloads

SingleAsync<TSource>(IQueryable<TSource>, CancellationToken)

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

SingleAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>, CancellationToken)

Asynchronously returns the only element of a sequence that satisfies a specified condition, and throws an exception if more than one such element exists.

SingleAsync<TSource>(IQueryable<TSource>, CancellationToken)

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

public static System.Threading.Tasks.Task<TSource> SingleAsync<TSource> (this System.Linq.IQueryable<TSource> source, System.Threading.CancellationToken cancellationToken = null);
static member SingleAsync : System.Linq.IQueryable<'Source> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<'Source>

Type Parameters

TSource

The type of the elements of source.

Parameters

source
IQueryable<TSource>

An IQueryable<T> to return the single element of.

cancellationToken
CancellationToken

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

Returns

Task<TSource>

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

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.

SingleAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>, CancellationToken)

Asynchronously returns the only element of a sequence that satisfies a specified condition, and throws an exception if more than one such element exists.

public static System.Threading.Tasks.Task<TSource> SingleAsync<TSource> (this System.Linq.IQueryable<TSource> source, System.Linq.Expressions.Expression<Func<TSource,bool>> predicate, System.Threading.CancellationToken cancellationToken = null);
static member SingleAsync : System.Linq.IQueryable<'Source> * System.Linq.Expressions.Expression<Func<'Source, bool>> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<'Source>

Type Parameters

TSource

The type of the elements of source.

Parameters

source
IQueryable<TSource>

An IQueryable<T> to return the single element of.

predicate
Expression<Func<TSource,Boolean>>

A function to test an element for a condition.

cancellationToken
CancellationToken

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

Returns

Task<TSource>

A task that represents the asynchronous operation. The task result contains the single element of the input sequence that 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