SqlSet<TResult>.FirstOrDefaultAsync(SqlSet.OperatorStringHandler, CancellationToken) Method
Returns the first element of the set that satisfies a condition or a default value if no such element is found.
Namespace: DbExtensions
Assembly: DbExtensions.dll
Overloads
| Name | Description |
|---|---|
| FirstOrDefaultAsync(CancellationToken) | Returns the first element of the set, or a default value if the set contains no elements. |
| FirstOrDefaultAsync(OperatorStringHandler, CancellationToken) | Returns the first element of the set that satisfies a condition or a default value if no such element is found. |
| FirstOrDefaultAsync(String, CancellationToken) | Returns the first element of the set that satisfies a condition or a default value if no such element is found. |
Syntax
public ValueTask<TResult> FirstOrDefaultAsync(
OperatorStringHandler predicate,
CancellationToken cancellationToken = default
)
Parameters
predicate OperatorStringHandler
A SQL expression to test each row for a condition.
cancellationToken CancellationToken (Optional)
The CancellationToken to monitor for cancellation requests. The default is None.
Return Value
ValueTask<TResult>
A default value if the set is empty or if no element passes the test specified by predicate; otherwise, the first element that passes the test specified by predicate.