Method FirstAsync
FirstAsync<TSource>(IQueryable<TSource>, CancellationToken)
Returns the first element of a sequence.
public static Task<TSource> FirstAsync<TSource>(this IQueryable<TSource> source, CancellationToken cancellationToken = default)
Parameters
source
IQueryable<TSource>The IQueryable<T> to return the first element of.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task<TSource>
The first element in
source
.
Type Parameters
TSource
The type of the elements of
source
.
FirstAsync<TSource>(IQueryable<TSource>, 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<TSource>An IQueryable<T> to return an element from.
predicate
Expression<Func<TSource, bool>>A function to test each element for a condition.
cancellationToken
CancellationTokenThe cancellation token.
Returns
- Task<TSource>
The first element in
source
that passes the test inpredicate
.
Type Parameters
TSource
The type of the elements of
source
.