Share via


EntityFrameworkQueryableExtensions.LastAsync Method

Definition

Overloads

LastAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>, CancellationToken)

Asynchronously returns the last element of a sequence that satisfies a specified condition.

LastAsync<TSource>(IQueryable<TSource>, CancellationToken)

Asynchronously returns the last element of a sequence.

LastAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource,Boolean>>, CancellationToken)

Asynchronously returns the last element of a sequence that satisfies a specified condition.

public static System.Threading.Tasks.Task<TSource> LastAsync<TSource> (this System.Linq.IQueryable<TSource> source, System.Linq.Expressions.Expression<Func<TSource,bool>> predicate, System.Threading.CancellationToken cancellationToken = default);
static member LastAsync : System.Linq.IQueryable<'Source> * System.Linq.Expressions.Expression<Func<'Source, bool>> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<'Source>
<Extension()>
Public Function LastAsync(Of TSource) (source As IQueryable(Of TSource), predicate As Expression(Of Func(Of TSource, Boolean)), Optional cancellationToken As CancellationToken = Nothing) As Task(Of TSource)

Type Parameters

TSource

The type of the elements of source.

Parameters

source
IQueryable<TSource>

An IQueryable<T> to return the last element of.

predicate
Expression<Func<TSource,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<TSource>

A task that represents the asynchronous operation. The task result contains the last element in source that passes the test in predicate.

Exceptions

source or predicate is null.

No element satisfies the condition in predicate.

-or-

source contains no elements.

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. See Avoiding DbContext threading issues for more information and examples.

See Querying data with EF Core for more information and examples.

Applies to

LastAsync<TSource>(IQueryable<TSource>, CancellationToken)

Asynchronously returns the last element of a sequence.

public static System.Threading.Tasks.Task<TSource> LastAsync<TSource> (this System.Linq.IQueryable<TSource> source, System.Threading.CancellationToken cancellationToken = default);
static member LastAsync : System.Linq.IQueryable<'Source> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<'Source>
<Extension()>
Public Function LastAsync(Of TSource) (source As IQueryable(Of TSource), Optional cancellationToken As CancellationToken = Nothing) As Task(Of TSource)

Type Parameters

TSource

The type of the elements of source.

Parameters

source
IQueryable<TSource>

An IQueryable<T> to return the last element of.

cancellationToken
CancellationToken

A CancellationToken to observe while waiting for the task to complete.

Returns

Task<TSource>

A task that represents the asynchronous operation. The task result contains the last element in source.

Exceptions

source is null.

source contains no elements.

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. See Avoiding DbContext threading issues for more information and examples.

See Querying data with EF Core for more information and examples.

Applies to