Method FirstAsync
| MongoDB CSharp Driver API Reference (original) (raw)
Namespace
Assembly
MongoDB.Driver.dll
FirstAsync(IQueryable, CancellationToken)
Returns the first element of a sequence.
public static Task<TSource> FirstAsync<TSource>(this IQueryable<TSource> source, CancellationToken cancellationToken = default)
Parameters
source
IQueryable
The IQueryable to return the first element of.
cancellationToken
CancellationToken
The cancellation token.
Returns
The first element in source
.
Type Parameters
TSource
The type of the elements of source
.
FirstAsync(IQueryable, Expression<Func<TSource, bool>>, CancellationToken)
Returns the first element of a sequence that satisfies a specified condition.
public static Task<TSource> FirstAsync<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate, CancellationToken cancellationToken = default)
Parameters
source
IQueryable
An IQueryable to return an element from.
predicate
Expression<Func<TSource, bool>>
A function to test each element for a condition.
cancellationToken
CancellationToken
The cancellation token.
Returns
The first element in source
that passes the test in predicate
.
Type Parameters
TSource
The type of the elements of source
.