Share via


DbRawSqlQuery<TElement>.FirstAsync Method

Definition

Overloads

FirstAsync()

Asynchronously returns the first element of the query.

FirstAsync(Func<TElement,Boolean>)

Asynchronously returns the first element of the query that satisfies a specified condition.

FirstAsync(CancellationToken)

Asynchronously returns the first element of the query.

FirstAsync(Func<TElement,Boolean>, CancellationToken)

Asynchronously returns the first element of the query that satisfies a specified condition.

FirstAsync()

Asynchronously returns the first element of the query.

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

Returns

Task<TElement>

A task that represents the asynchronous operation. The task result contains the first element in 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

FirstAsync(Func<TElement,Boolean>)

Asynchronously returns the first element of the query that satisfies a specified condition.

public System.Threading.Tasks.Task<TElement> FirstAsync (Func<TElement,bool> predicate);
member this.FirstAsync : Func<'Element, bool> -> System.Threading.Tasks.Task<'Element>
Public Function FirstAsync (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 first element in the query result that satisfies a specified condition.

Exceptions

predicate is null .

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

FirstAsync(CancellationToken)

Asynchronously returns the first element of the query.

public System.Threading.Tasks.Task<TElement> FirstAsync (System.Threading.CancellationToken cancellationToken);
member this.FirstAsync : 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 first element in 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

FirstAsync(Func<TElement,Boolean>, CancellationToken)

Asynchronously returns the first element of the query that satisfies a specified condition.

public System.Threading.Tasks.Task<TElement> FirstAsync (Func<TElement,bool> predicate, System.Threading.CancellationToken cancellationToken);
member this.FirstAsync : 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 first element in the query result that satisfies a specified condition.

Exceptions

predicate is null .

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