Lingua

EntityFrameworkQueryableExtensions.MaxByAsync<TSource,TKey> Method

Definition

Asynchronously returns the maximum value in a generic IQueryable<T> according to a specified key selector function.

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

Type Parameters

TSource

The type of the elements of source.

TKey

The type of the value returned by the function represented by keySelector.

Parameters

source
IQueryable<TSource>

A sequence of values to determine the maximum value of.

keySelector
Expression<Func<TSource,TKey>>

A function to extract the key for each element.

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 contains the value with the maximum key in the sequence.

Exceptions

source or keySelector 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