DbRawSqlQuery<TElement>.FirstOrDefaultAsync Method

Definition

Overloads

FirstOrDefaultAsync()

Asynchronously returns the first element of the query, or a default value if the the query result contains no elements.

FirstOrDefaultAsync(Func<TElement,Boolean>)

Asynchronously returns the first element of the query that satisfies a specified condition or a default value if no such element is found.

FirstOrDefaultAsync(CancellationToken)

Asynchronously returns the first element of the query, or a default value if the the query result contains no elements.

FirstOrDefaultAsync(Func<TElement,Boolean>, CancellationToken)

Asynchronously returns the first element of the query that satisfies a specified condition or a default value if no such element is found.

FirstOrDefaultAsync()

Asynchronously returns the first element of the query, or a default value if the the query result contains no elements.

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

Returns

Task<TElement>

A task that represents the asynchronous operation. The task result contains default ( TElement ) if query result is empty; otherwise, the first element in the query result.

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

FirstOrDefaultAsync(Func<TElement,Boolean>)

Asynchronously returns the first element of the query that satisfies a specified condition or a default value if no such element is found.

public System.Threading.Tasks.Task<TElement> FirstOrDefaultAsync (Func<TElement,bool> predicate);
member this.FirstOrDefaultAsync : Func<'Element, bool> -> System.Threading.Tasks.Task<'Element>
Public Function FirstOrDefaultAsync (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 default ( TElement ) if query result is empty or if no element passes the test specified by predicate; otherwise, the first element in the query result that passes the test specified by predicate .

Exceptions

predicate is null .

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

FirstOrDefaultAsync(CancellationToken)

Asynchronously returns the first element of the query, or a default value if the the query result contains no elements.

public System.Threading.Tasks.Task<TElement> FirstOrDefaultAsync (System.Threading.CancellationToken cancellationToken);
member this.FirstOrDefaultAsync : 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 default ( TElement ) if query result is empty; otherwise, the first element in the query result.

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

FirstOrDefaultAsync(Func<TElement,Boolean>, CancellationToken)

Asynchronously returns the first element of the query that satisfies a specified condition or a default value if no such element is found.

public System.Threading.Tasks.Task<TElement> FirstOrDefaultAsync (Func<TElement,bool> predicate, System.Threading.CancellationToken cancellationToken);
member this.FirstOrDefaultAsync : 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 default ( TElement ) if query result is empty or if no element passes the test specified by predicate; otherwise, the first element in the query result that passes the test specified by predicate .

Exceptions

predicate is null .

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