DbRawSqlQuery<TElement>.FirstOrDefaultAsync Method
Asynchronously returns the first element of the query, or a default value if the query result contains no elements.
Assembly: EntityFramework (in EntityFramework.dll)
Name | Description | |
---|---|---|
![]() | FirstOrDefaultAsync() | Asynchronously returns the first element of the query, or a default value if the the query result contains no elements. |
![]() | 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>) | Asynchronously returns the first element of the query that satisfies a specified condition or a default value if no such element is found. |
![]() | 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. |
DbRawSqlQuery<TElement>.FirstOrDefaultAsync Method ()
Asynchronously returns the first element of the query, or a default value if the the query result contains no elements.
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>.FirstOrDefaultAsync Method (CancellationToken)
Asynchronously returns the first element of the query, or a default value if the the query result contains no elements.
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 default ( TElement ) if query result is empty; otherwise, the first element in the query result.
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>.FirstOrDefaultAsync Method (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.
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 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 .
Exception | Condition |
---|---|
ArgumentNullException | predicate is null . |
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>.FirstOrDefaultAsync Method (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 Task<TElement> FirstOrDefaultAsync( 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 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 .
Exception | Condition |
---|---|
ArgumentNullException | predicate is null . |
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.