Table of Contents

Class LinqToDBExtensionsAdapter

Namespace
LinqToDB.EntityFrameworkCore
Assembly
linq2db.EntityFrameworkCore.dll

LINQ To DB async extensions adapter to call EF.Core functionality instead of default implementation.

public sealed class LinqToDBExtensionsAdapter : IExtensionsAdapter
Inheritance
LinqToDBExtensionsAdapter
Implements

Methods

AllAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource, bool>>, CancellationToken)

Asynchronously determines whether all the elements of a sequence satisfy a condition.

public Task<bool> AllAsync<TSource>(IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate, CancellationToken token)

Parameters

source IQueryable<TSource>

An IQueryable<T> whose elements to test for a condition.

predicate Expression<Func<TSource, bool>>

A function to test each element for a condition.

token CancellationToken

Returns

Task<bool>

A task that represents the asynchronous operation. The task result contains true if every element of the source sequence passes the test in the specified predicate; otherwise, false.

Type Parameters

TSource

The type of the elements of source.

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.

Exceptions

ArgumentNullException

source or predicate is null.

OperationCanceledException

If the CancellationToken is canceled.

AnyAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource, bool>>, CancellationToken)

Asynchronously determines whether any element of a sequence satisfies a condition.

public Task<bool> AnyAsync<TSource>(IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate, CancellationToken token)

Parameters

source IQueryable<TSource>

An IQueryable<T> whose elements to test for a condition.

predicate Expression<Func<TSource, bool>>

A function to test each element for a condition.

token CancellationToken

Returns

Task<bool>

A task that represents the asynchronous operation. The task result contains true if any elements in the source sequence pass the test in the specified predicate; otherwise, false.

Type Parameters

TSource

The type of the elements of source.

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.

Exceptions

ArgumentNullException

source or predicate is null.

OperationCanceledException

If the CancellationToken is canceled.

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

Asynchronously determines whether a sequence contains any elements.

public Task<bool> AnyAsync<TSource>(IQueryable<TSource> source, CancellationToken token)

Parameters

source IQueryable<TSource>

An IQueryable<T> to check for being empty.

token CancellationToken

Returns

Task<bool>

A task that represents the asynchronous operation. The task result contains true if the source sequence contains any elements; otherwise, false.

Type Parameters

TSource

The type of the elements of source.

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.

Exceptions

ArgumentNullException

source is null.

OperationCanceledException

If the CancellationToken is canceled.

AsAsyncEnumerable<TSource>(IQueryable<TSource>)

Returns an IAsyncEnumerable<T> which can be enumerated asynchronously.

public IAsyncEnumerable<TSource> AsAsyncEnumerable<TSource>(IQueryable<TSource> source)

Parameters

source IQueryable<TSource>

An IQueryable<T> to enumerate.

Returns

IAsyncEnumerable<TSource>

The query results.

Type Parameters

TSource

The type of the elements of source.

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.

Exceptions

InvalidOperationException

source is null.

ArgumentNullException

source is not a IAsyncEnumerable<T>.

AverageAsync(IQueryable<decimal>, CancellationToken)

Asynchronously computes the average of a sequence of values.

public Task<decimal> AverageAsync(IQueryable<decimal> source, CancellationToken token)

Parameters

source IQueryable<decimal>

A sequence of values to calculate the average of.

token CancellationToken

Returns

Task<decimal>

A task that represents the asynchronous operation. The task result contains the average of the sequence of values.

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.

Exceptions

ArgumentNullException

source is null.

InvalidOperationException

source contains no elements.

OperationCanceledException

If the CancellationToken is canceled.

AverageAsync(IQueryable<double>, CancellationToken)

Asynchronously computes the average of a sequence of values.

public Task<double> AverageAsync(IQueryable<double> source, CancellationToken token)

Parameters

source IQueryable<double>

A sequence of values to calculate the average of.

token CancellationToken

Returns

Task<double>

A task that represents the asynchronous operation. The task result contains the average of the sequence of values.

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.

Exceptions

ArgumentNullException

source is null.

InvalidOperationException

source contains no elements.

OperationCanceledException

If the CancellationToken is canceled.

AverageAsync(IQueryable<int>, CancellationToken)

Asynchronously computes the average of a sequence of values.

public Task<double> AverageAsync(IQueryable<int> source, CancellationToken token)

Parameters

source IQueryable<int>

A sequence of values to calculate the average of.

token CancellationToken

Returns

Task<double>

A task that represents the asynchronous operation. The task result contains the average of the sequence of values.

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.

Exceptions

ArgumentNullException

source is null.

InvalidOperationException

source contains no elements.

OperationCanceledException

If the CancellationToken is canceled.

AverageAsync(IQueryable<long>, CancellationToken)

Asynchronously computes the average of a sequence of values.

public Task<double> AverageAsync(IQueryable<long> source, CancellationToken token)

Parameters

source IQueryable<long>

A sequence of values to calculate the average of.

token CancellationToken

Returns

Task<double>

A task that represents the asynchronous operation. The task result contains the average of the sequence of values.

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.

Exceptions

ArgumentNullException

source is null.

InvalidOperationException

source contains no elements.

OperationCanceledException

If the CancellationToken is canceled.

AverageAsync(IQueryable<decimal?>, CancellationToken)

Asynchronously computes the average of a sequence of values.

public Task<decimal?> AverageAsync(IQueryable<decimal?> source, CancellationToken token)

Parameters

source IQueryable<decimal?>

A sequence of values to calculate the average of.

token CancellationToken

Returns

Task<decimal?>

A task that represents the asynchronous operation. The task result contains the average of the sequence of values.

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.

Exceptions

ArgumentNullException

source is null.

OperationCanceledException

If the CancellationToken is canceled.

AverageAsync(IQueryable<double?>, CancellationToken)

Asynchronously computes the average of a sequence of values.

public Task<double?> AverageAsync(IQueryable<double?> source, CancellationToken token)

Parameters

source IQueryable<double?>

A sequence of values to calculate the average of.

token CancellationToken

Returns

Task<double?>

A task that represents the asynchronous operation. The task result contains the average of the sequence of values.

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.

Exceptions

ArgumentNullException

source is null.

OperationCanceledException

If the CancellationToken is canceled.

AverageAsync(IQueryable<int?>, CancellationToken)

Asynchronously computes the average of a sequence of values.

public Task<double?> AverageAsync(IQueryable<int?> source, CancellationToken token)

Parameters

source IQueryable<int?>

A sequence of values to calculate the average of.

token CancellationToken

Returns

Task<double?>

A task that represents the asynchronous operation. The task result contains the average of the sequence of values.

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.

Exceptions

ArgumentNullException

source is null.

OperationCanceledException

If the CancellationToken is canceled.

AverageAsync(IQueryable<long?>, CancellationToken)

Asynchronously computes the average of a sequence of values.

public Task<double?> AverageAsync(IQueryable<long?> source, CancellationToken token)

Parameters

source IQueryable<long?>

A sequence of values to calculate the average of.

token CancellationToken

Returns

Task<double?>

A task that represents the asynchronous operation. The task result contains the average of the sequence of values.

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.

Exceptions

ArgumentNullException

source is null.

OperationCanceledException

If the CancellationToken is canceled.

AverageAsync(IQueryable<float?>, CancellationToken)

Asynchronously computes the average of a sequence of values.

public Task<float?> AverageAsync(IQueryable<float?> source, CancellationToken token)

Parameters

source IQueryable<float?>

A sequence of values to calculate the average of.

token CancellationToken

Returns

Task<float?>

A task that represents the asynchronous operation. The task result contains the average of the sequence of values.

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.

Exceptions

ArgumentNullException

source is null.

OperationCanceledException

If the CancellationToken is canceled.

AverageAsync(IQueryable<float>, CancellationToken)

Asynchronously computes the average of a sequence of values.

public Task<float> AverageAsync(IQueryable<float> source, CancellationToken token)

Parameters

source IQueryable<float>

A sequence of values to calculate the average of.

token CancellationToken

Returns

Task<float>

A task that represents the asynchronous operation. The task result contains the average of the sequence of values.

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.

Exceptions

ArgumentNullException

source is null.

InvalidOperationException

source contains no elements.

OperationCanceledException

If the CancellationToken is canceled.

AverageAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource, decimal>>, CancellationToken)

Asynchronously computes the average of a sequence of values that is obtained by invoking a projection function on each element of the input sequence.

public Task<decimal> AverageAsync<TSource>(IQueryable<TSource> source, Expression<Func<TSource, decimal>> selector, CancellationToken token)

Parameters

source IQueryable<TSource>

A sequence of values of type TSource.

selector Expression<Func<TSource, decimal>>

A projection function to apply to each element.

token CancellationToken

Returns

Task<decimal>

A task that represents the asynchronous operation. The task result contains the average of the projected values.

Type Parameters

TSource

The type of the elements of source.

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.

Exceptions

ArgumentNullException

source or selector is null.

InvalidOperationException

source contains no elements.

OperationCanceledException

If the CancellationToken is canceled.

AverageAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource, double>>, CancellationToken)

Asynchronously computes the average of a sequence of values that is obtained by invoking a projection function on each element of the input sequence.

public Task<double> AverageAsync<TSource>(IQueryable<TSource> source, Expression<Func<TSource, double>> selector, CancellationToken token)

Parameters

source IQueryable<TSource>

A sequence of values of type TSource.

selector Expression<Func<TSource, double>>

A projection function to apply to each element.

token CancellationToken

Returns

Task<double>

A task that represents the asynchronous operation. The task result contains the average of the projected values.

Type Parameters

TSource

The type of the elements of source.

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.

Exceptions

ArgumentNullException

source or selector is null.

InvalidOperationException

source contains no elements.

OperationCanceledException

If the CancellationToken is canceled.

AverageAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource, int>>, CancellationToken)

Asynchronously computes the average of a sequence of values that is obtained by invoking a projection function on each element of the input sequence.

public Task<double> AverageAsync<TSource>(IQueryable<TSource> source, Expression<Func<TSource, int>> selector, CancellationToken token)

Parameters

source IQueryable<TSource>

A sequence of values of type TSource.

selector Expression<Func<TSource, int>>

A projection function to apply to each element.

token CancellationToken

Returns

Task<double>

A task that represents the asynchronous operation. The task result contains the average of the projected values.

Type Parameters

TSource

The type of the elements of source.

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.

Exceptions

ArgumentNullException

source or selector is null.

InvalidOperationException

source contains no elements.

OperationCanceledException

If the CancellationToken is canceled.

AverageAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource, long>>, CancellationToken)

Asynchronously computes the average of a sequence of values that is obtained by invoking a projection function on each element of the input sequence.

public Task<double> AverageAsync<TSource>(IQueryable<TSource> source, Expression<Func<TSource, long>> selector, CancellationToken token)

Parameters

source IQueryable<TSource>

A sequence of values of type TSource.

selector Expression<Func<TSource, long>>

A projection function to apply to each element.

token CancellationToken

Returns

Task<double>

A task that represents the asynchronous operation. The task result contains the average of the projected values.

Type Parameters

TSource

The type of the elements of source.

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.

Exceptions

ArgumentNullException

source or selector is null.

InvalidOperationException

source contains no elements.

OperationCanceledException

If the CancellationToken is canceled.

AverageAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource, decimal?>>, CancellationToken)

Asynchronously computes the average of a sequence of values that is obtained by invoking a projection function on each element of the input sequence.

public Task<decimal?> AverageAsync<TSource>(IQueryable<TSource> source, Expression<Func<TSource, decimal?>> selector, CancellationToken token)

Parameters

source IQueryable<TSource>

A sequence of values of type TSource.

selector Expression<Func<TSource, decimal?>>

A projection function to apply to each element.

token CancellationToken

Returns

Task<decimal?>

A task that represents the asynchronous operation. The task result contains the average of the projected values.

Type Parameters

TSource

The type of the elements of source.

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.

Exceptions

ArgumentNullException

source or selector is null.

OperationCanceledException

If the CancellationToken is canceled.

AverageAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource, double?>>, CancellationToken)

Asynchronously computes the average of a sequence of values that is obtained by invoking a projection function on each element of the input sequence.

public Task<double?> AverageAsync<TSource>(IQueryable<TSource> source, Expression<Func<TSource, double?>> selector, CancellationToken token)

Parameters

source IQueryable<TSource>

A sequence of values of type TSource.

selector Expression<Func<TSource, double?>>

A projection function to apply to each element.

token CancellationToken

Returns

Task<double?>

A task that represents the asynchronous operation. The task result contains the average of the projected values.

Type Parameters

TSource

The type of the elements of source.

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.

Exceptions

ArgumentNullException

source or selector is null.

OperationCanceledException

If the CancellationToken is canceled.

AverageAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource, int?>>, CancellationToken)

Asynchronously computes the average of a sequence of values that is obtained by invoking a projection function on each element of the input sequence.

public Task<double?> AverageAsync<TSource>(IQueryable<TSource> source, Expression<Func<TSource, int?>> selector, CancellationToken token)

Parameters

source IQueryable<TSource>

A sequence of values of type TSource.

selector Expression<Func<TSource, int?>>

A projection function to apply to each element.

token CancellationToken

Returns

Task<double?>

A task that represents the asynchronous operation. The task result contains the average of the projected values.

Type Parameters

TSource

The type of the elements of source.

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.

Exceptions

ArgumentNullException

source or selector is null.

OperationCanceledException

If the CancellationToken is canceled.

AverageAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource, long?>>, CancellationToken)

Asynchronously computes the average of a sequence of values that is obtained by invoking a projection function on each element of the input sequence.

public Task<double?> AverageAsync<TSource>(IQueryable<TSource> source, Expression<Func<TSource, long?>> selector, CancellationToken token)

Parameters

source IQueryable<TSource>

A sequence of values of type TSource.

selector Expression<Func<TSource, long?>>

A projection function to apply to each element.

token CancellationToken

Returns

Task<double?>

A task that represents the asynchronous operation. The task result contains the average of the projected values.

Type Parameters

TSource

The type of the elements of source.

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.

Exceptions

ArgumentNullException

source or selector is null.

OperationCanceledException

If the CancellationToken is canceled.

AverageAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource, float?>>, CancellationToken)

Asynchronously computes the average of a sequence of values that is obtained by invoking a projection function on each element of the input sequence.

public Task<float?> AverageAsync<TSource>(IQueryable<TSource> source, Expression<Func<TSource, float?>> selector, CancellationToken token)

Parameters

source IQueryable<TSource>

A sequence of values of type TSource.

selector Expression<Func<TSource, float?>>

A projection function to apply to each element.

token CancellationToken

Returns

Task<float?>

A task that represents the asynchronous operation. The task result contains the average of the projected values.

Type Parameters

TSource

The type of the elements of source.

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.

Exceptions

ArgumentNullException

source or selector is null.

OperationCanceledException

If the CancellationToken is canceled.

AverageAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource, float>>, CancellationToken)

Asynchronously computes the average of a sequence of values that is obtained by invoking a projection function on each element of the input sequence.

public Task<float> AverageAsync<TSource>(IQueryable<TSource> source, Expression<Func<TSource, float>> selector, CancellationToken token)

Parameters

source IQueryable<TSource>

A sequence of values of type TSource.

selector Expression<Func<TSource, float>>

A projection function to apply to each element.

token CancellationToken

Returns

Task<float>

A task that represents the asynchronous operation. The task result contains the average of the projected values.

Type Parameters

TSource

The type of the elements of source.

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.

Exceptions

ArgumentNullException

source or selector is null.

InvalidOperationException

source contains no elements.

OperationCanceledException

If the CancellationToken is canceled.

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

Asynchronously determines whether a sequence contains a specified element by using the default equality comparer.

public Task<bool> ContainsAsync<TSource>(IQueryable<TSource> source, TSource item, CancellationToken token)

Parameters

source IQueryable<TSource>

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

item TSource

The object to locate in the sequence.

token CancellationToken

Returns

Task<bool>

A task that represents the asynchronous operation. The task result contains true if the input sequence contains the specified value; otherwise, false.

Type Parameters

TSource

The type of the elements of source.

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.

Exceptions

ArgumentNullException

source is null.

OperationCanceledException

If the CancellationToken is canceled.

CountAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource, bool>>, CancellationToken)

Asynchronously returns the number of elements in a sequence that satisfy a condition.

public Task<int> CountAsync<TSource>(IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate, CancellationToken token)

Parameters

source IQueryable<TSource>

An IQueryable<T> that contains the elements to be counted.

predicate Expression<Func<TSource, bool>>

A function to test each element for a condition.

token CancellationToken

Returns

Task<int>

A task that represents the asynchronous operation. The task result contains the number of elements in the sequence that satisfy the condition in the predicate function.

Type Parameters

TSource

The type of the elements of source.

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.

Exceptions

ArgumentNullException

source or predicate is null.

OperationCanceledException

If the CancellationToken is canceled.

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

Asynchronously returns the number of elements in a sequence.

public Task<int> CountAsync<TSource>(IQueryable<TSource> source, CancellationToken token)

Parameters

source IQueryable<TSource>

An IQueryable<T> that contains the elements to be counted.

token CancellationToken

Returns

Task<int>

A task that represents the asynchronous operation. The task result contains the number of elements in the input sequence.

Type Parameters

TSource

The type of the elements of source.

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.

Exceptions

ArgumentNullException

source is null.

OperationCanceledException

If the CancellationToken is canceled.

FirstAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource, bool>>, CancellationToken)

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

public Task<TSource> FirstAsync<TSource>(IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate, CancellationToken token)

Parameters

source IQueryable<TSource>

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

predicate Expression<Func<TSource, bool>>

A function to test each element for a condition.

token CancellationToken

Returns

Task<TSource>

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

Type Parameters

TSource

The type of the elements of source.

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.

Exceptions

ArgumentNullException

source or predicate is null.

InvalidOperationException

No element satisfies the condition in predicate

-or -

source contains no elements.

OperationCanceledException

If the CancellationToken is canceled.

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

Asynchronously returns the first element of a sequence.

public Task<TSource> FirstAsync<TSource>(IQueryable<TSource> source, CancellationToken token)

Parameters

source IQueryable<TSource>

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

token CancellationToken

Returns

Task<TSource>

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

Type Parameters

TSource

The type of the elements of source.

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.

Exceptions

ArgumentNullException

source is null.

InvalidOperationException

source contains no elements.

OperationCanceledException

If the CancellationToken is canceled.

FirstOrDefaultAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource, bool>>, CancellationToken)

Asynchronously returns the first element of a sequence that satisfies a specified condition or a default value if no such element is found.

public Task<TSource?> FirstOrDefaultAsync<TSource>(IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate, CancellationToken token)

Parameters

source IQueryable<TSource>

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

predicate Expression<Func<TSource, bool>>

A function to test each element for a condition.

token CancellationToken

Returns

Task<TSource>

A task that represents the asynchronous operation. The task result contains default ( TSource ) if source is empty or if no element passes the test specified by predicate, otherwise, the first element in source that passes the test specified by predicate.

Type Parameters

TSource

The type of the elements of source.

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.

Exceptions

ArgumentNullException

source or predicate is null.

OperationCanceledException

If the CancellationToken is canceled.

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

Asynchronously returns the first element of a sequence, or a default value if the sequence contains no elements.

public Task<TSource?> FirstOrDefaultAsync<TSource>(IQueryable<TSource> source, CancellationToken token)

Parameters

source IQueryable<TSource>

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

token CancellationToken

Returns

Task<TSource>

A task that represents the asynchronous operation. The task result contains default ( TSource ) if source is empty; otherwise, the first element in source.

Type Parameters

TSource

The type of the elements of source.

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.

Exceptions

ArgumentNullException

source is null.

OperationCanceledException

If the CancellationToken is canceled.

ForEachAsync<TSource>(IQueryable<TSource>, Action<TSource>, CancellationToken)

Asynchronously enumerates the query results and performs the specified action on each element.

public Task ForEachAsync<TSource>(IQueryable<TSource> source, Action<TSource> action, CancellationToken token)

Parameters

source IQueryable<TSource>

An IQueryable<T> to enumerate.

action Action<TSource>

The action to perform on each element.

token CancellationToken

Returns

Task

A task that represents the asynchronous operation.

Type Parameters

TSource

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.

Exceptions

ArgumentNullException

source or action is null.

OperationCanceledException

If the CancellationToken is canceled.

LongCountAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource, bool>>, CancellationToken)

Asynchronously returns a long that represents the number of elements in a sequence that satisfy a condition.

public Task<long> LongCountAsync<TSource>(IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate, CancellationToken token)

Parameters

source IQueryable<TSource>

An IQueryable<T> that contains the elements to be counted.

predicate Expression<Func<TSource, bool>>

A function to test each element for a condition.

token CancellationToken

Returns

Task<long>

A task that represents the asynchronous operation. The task result contains the number of elements in the sequence that satisfy the condition in the predicate function.

Type Parameters

TSource

The type of the elements of source.

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.

Exceptions

ArgumentNullException

source or predicate is null.

OperationCanceledException

If the CancellationToken is canceled.

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

Asynchronously returns a long that represents the total number of elements in a sequence.

public Task<long> LongCountAsync<TSource>(IQueryable<TSource> source, CancellationToken token)

Parameters

source IQueryable<TSource>

An IQueryable<T> that contains the elements to be counted.

token CancellationToken

Returns

Task<long>

A task that represents the asynchronous operation. The task result contains the number of elements in the input sequence.

Type Parameters

TSource

The type of the elements of source.

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.

Exceptions

ArgumentNullException

source is null.

OperationCanceledException

If the CancellationToken is canceled.

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

Asynchronously returns the maximum value of a sequence.

public Task<TSource?> MaxAsync<TSource>(IQueryable<TSource> source, CancellationToken token)

Parameters

source IQueryable<TSource>

An IQueryable<T> that contains the elements to determine the maximum of.

token CancellationToken

Returns

Task<TSource>

A task that represents the asynchronous operation. The task result contains the maximum value in the sequence.

Type Parameters

TSource

The type of the elements of source.

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.

Exceptions

ArgumentNullException

source is null.

InvalidOperationException

source contains no elements.

OperationCanceledException

If the CancellationToken is canceled.

MaxAsync<TSource, TResult>(IQueryable<TSource>, Expression<Func<TSource, TResult>>, CancellationToken)

Asynchronously invokes a projection function on each element of a sequence and returns the maximum resulting value.

public Task<TResult?> MaxAsync<TSource, TResult>(IQueryable<TSource> source, Expression<Func<TSource, TResult>> selector, CancellationToken token)

Parameters

source IQueryable<TSource>

An IQueryable<T> that contains the elements to determine the maximum of.

selector Expression<Func<TSource, TResult>>

A projection function to apply to each element.

token CancellationToken

Returns

Task<TResult>

A task that represents the asynchronous operation. The task result contains the maximum value in the sequence.

Type Parameters

TSource

The type of the elements of source.

TResult

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

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.

Exceptions

ArgumentNullException

source or selector is null.

InvalidOperationException

source contains no elements.

OperationCanceledException

If the CancellationToken is canceled.

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

Asynchronously returns the minimum value of a sequence.

public Task<TSource?> MinAsync<TSource>(IQueryable<TSource> source, CancellationToken token)

Parameters

source IQueryable<TSource>

An IQueryable<T> that contains the elements to determine the minimum of.

token CancellationToken

Returns

Task<TSource>

A task that represents the asynchronous operation. The task result contains the minimum value in the sequence.

Type Parameters

TSource

The type of the elements of source.

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.

Exceptions

ArgumentNullException

source is null.

InvalidOperationException

source contains no elements.

OperationCanceledException

If the CancellationToken is canceled.

MinAsync<TSource, TResult>(IQueryable<TSource>, Expression<Func<TSource, TResult>>, CancellationToken)

Asynchronously invokes a projection function on each element of a sequence and returns the minimum resulting value.

public Task<TResult?> MinAsync<TSource, TResult>(IQueryable<TSource> source, Expression<Func<TSource, TResult>> selector, CancellationToken token)

Parameters

source IQueryable<TSource>

An IQueryable<T> that contains the elements to determine the minimum of.

selector Expression<Func<TSource, TResult>>

A projection function to apply to each element.

token CancellationToken

Returns

Task<TResult>

A task that represents the asynchronous operation. The task result contains the minimum value in the sequence.

Type Parameters

TSource

The type of the elements of source.

TResult

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

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.

Exceptions

ArgumentNullException

source or selector is null.

InvalidOperationException

source contains no elements.

OperationCanceledException

If the CancellationToken is canceled.

SingleAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource, bool>>, CancellationToken)

Asynchronously returns the only element of a sequence that satisfies a specified condition, and throws an exception if more than one such element exists.

public Task<TSource> SingleAsync<TSource>(IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate, CancellationToken token)

Parameters

source IQueryable<TSource>

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

predicate Expression<Func<TSource, bool>>

A function to test an element for a condition.

token CancellationToken

Returns

Task<TSource>

A task that represents the asynchronous operation. The task result contains the single element of the input sequence that satisfies the condition in predicate.

Type Parameters

TSource

The type of the elements of source.

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.

Exceptions

ArgumentNullException

source or predicate is null.

InvalidOperationException

No element satisfies the condition in predicate.

-or-

More than one element satisfies the condition in predicate.

-or-

source contains no elements.

OperationCanceledException

If the CancellationToken is canceled.

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

Asynchronously returns the only element of a sequence, and throws an exception if there is not exactly one element in the sequence.

public Task<TSource> SingleAsync<TSource>(IQueryable<TSource> source, CancellationToken token)

Parameters

source IQueryable<TSource>

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

token CancellationToken

Returns

Task<TSource>

A task that represents the asynchronous operation. The task result contains the single element of the input sequence.

Type Parameters

TSource

The type of the elements of source.

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.

Exceptions

ArgumentNullException

source is null.

InvalidOperationException

source contains more than one elements.

-or-

source contains no elements.

OperationCanceledException

If the CancellationToken is canceled.

SingleOrDefaultAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource, bool>>, CancellationToken)

Asynchronously returns the only element of a sequence that satisfies a specified condition or a default value if no such element exists; this method throws an exception if more than one element satisfies the condition.

public Task<TSource?> SingleOrDefaultAsync<TSource>(IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate, CancellationToken token)

Parameters

source IQueryable<TSource>

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

predicate Expression<Func<TSource, bool>>

A function to test an element for a condition.

token CancellationToken

Returns

Task<TSource>

A task that represents the asynchronous operation. The task result contains the single element of the input sequence that satisfies the condition in predicate, or default ( TSource ) if no such element is found.

Type Parameters

TSource

The type of the elements of source.

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.

Exceptions

ArgumentNullException

source or predicate is null.

InvalidOperationException

More than one element satisfies the condition in predicate.

OperationCanceledException

If the CancellationToken is canceled.

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

Asynchronously returns the only element of a sequence, or a default value if the sequence is empty; this method throws an exception if there is more than one element in the sequence.

public Task<TSource?> SingleOrDefaultAsync<TSource>(IQueryable<TSource> source, CancellationToken token)

Parameters

source IQueryable<TSource>

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

token CancellationToken

Returns

Task<TSource>

A task that represents the asynchronous operation. The task result contains the single element of the input sequence, or default ( TSource) if the sequence contains no elements.

Type Parameters

TSource

The type of the elements of source.

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.

Exceptions

ArgumentNullException

source is null.

InvalidOperationException

source contains more than one element.

OperationCanceledException

If the CancellationToken is canceled.

SumAsync(IQueryable<decimal>, CancellationToken)

Asynchronously computes the sum of a sequence of values.

public Task<decimal> SumAsync(IQueryable<decimal> source, CancellationToken token)

Parameters

source IQueryable<decimal>

A sequence of values to calculate the sum of.

token CancellationToken

Returns

Task<decimal>

A task that represents the asynchronous operation. The task result contains the sum of the values in the sequence.

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.

Exceptions

ArgumentNullException

source is null.

OperationCanceledException

If the CancellationToken is canceled.

SumAsync(IQueryable<double>, CancellationToken)

Asynchronously computes the sum of a sequence of values.

public Task<double> SumAsync(IQueryable<double> source, CancellationToken token)

Parameters

source IQueryable<double>

A sequence of values to calculate the sum of.

token CancellationToken

Returns

Task<double>

A task that represents the asynchronous operation. The task result contains the sum of the values in the sequence.

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.

Exceptions

ArgumentNullException

source is null.

OperationCanceledException

If the CancellationToken is canceled.

SumAsync(IQueryable<int>, CancellationToken)

Asynchronously computes the sum of a sequence of values.

public Task<int> SumAsync(IQueryable<int> source, CancellationToken token)

Parameters

source IQueryable<int>

A sequence of values to calculate the sum of.

token CancellationToken

Returns

Task<int>

A task that represents the asynchronous operation. The task result contains the sum of the values in the sequence.

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.

Exceptions

ArgumentNullException

source is null.

OperationCanceledException

If the CancellationToken is canceled.

SumAsync(IQueryable<long>, CancellationToken)

Asynchronously computes the sum of a sequence of values.

public Task<long> SumAsync(IQueryable<long> source, CancellationToken token)

Parameters

source IQueryable<long>

A sequence of values to calculate the sum of.

token CancellationToken

Returns

Task<long>

A task that represents the asynchronous operation. The task result contains the sum of the values in the sequence.

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.

Exceptions

ArgumentNullException

source is null.

OperationCanceledException

If the CancellationToken is canceled.

SumAsync(IQueryable<decimal?>, CancellationToken)

Asynchronously computes the sum of a sequence of values.

public Task<decimal?> SumAsync(IQueryable<decimal?> source, CancellationToken token)

Parameters

source IQueryable<decimal?>

A sequence of values to calculate the sum of.

token CancellationToken

Returns

Task<decimal?>

A task that represents the asynchronous operation. The task result contains the sum of the values in the sequence.

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.

Exceptions

ArgumentNullException

source is null.

OperationCanceledException

If the CancellationToken is canceled.

SumAsync(IQueryable<double?>, CancellationToken)

Asynchronously computes the sum of a sequence of values.

public Task<double?> SumAsync(IQueryable<double?> source, CancellationToken token)

Parameters

source IQueryable<double?>

A sequence of values to calculate the sum of.

token CancellationToken

Returns

Task<double?>

A task that represents the asynchronous operation. The task result contains the sum of the values in the sequence.

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.

Exceptions

ArgumentNullException

source is null.

OperationCanceledException

If the CancellationToken is canceled.

SumAsync(IQueryable<int?>, CancellationToken)

Asynchronously computes the sum of a sequence of values.

public Task<int?> SumAsync(IQueryable<int?> source, CancellationToken token)

Parameters

source IQueryable<int?>

A sequence of values to calculate the sum of.

token CancellationToken

Returns

Task<int?>

A task that represents the asynchronous operation. The task result contains the sum of the values in the sequence.

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.

Exceptions

ArgumentNullException

source is null.

OperationCanceledException

If the CancellationToken is canceled.

SumAsync(IQueryable<long?>, CancellationToken)

Asynchronously computes the sum of a sequence of values.

public Task<long?> SumAsync(IQueryable<long?> source, CancellationToken token)

Parameters

source IQueryable<long?>

A sequence of values to calculate the sum of.

token CancellationToken

Returns

Task<long?>

A task that represents the asynchronous operation. The task result contains the sum of the values in the sequence.

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.

Exceptions

ArgumentNullException

source is null.

OperationCanceledException

If the CancellationToken is canceled.

SumAsync(IQueryable<float?>, CancellationToken)

Asynchronously computes the sum of a sequence of values.

public Task<float?> SumAsync(IQueryable<float?> source, CancellationToken token)

Parameters

source IQueryable<float?>

A sequence of values to calculate the sum of.

token CancellationToken

Returns

Task<float?>

A task that represents the asynchronous operation. The task result contains the sum of the values in the sequence.

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.

Exceptions

ArgumentNullException

source is null.

OperationCanceledException

If the CancellationToken is canceled.

SumAsync(IQueryable<float>, CancellationToken)

Asynchronously computes the sum of a sequence of values.

public Task<float> SumAsync(IQueryable<float> source, CancellationToken token)

Parameters

source IQueryable<float>

A sequence of values to calculate the sum of.

token CancellationToken

Returns

Task<float>

A task that represents the asynchronous operation. The task result contains the sum of the values in the sequence.

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.

Exceptions

ArgumentNullException

source is null.

OperationCanceledException

If the CancellationToken is canceled.

SumAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource, decimal>>, CancellationToken)

Asynchronously computes the sum of the sequence of values that is obtained by invoking a projection function on each element of the input sequence.

public Task<decimal> SumAsync<TSource>(IQueryable<TSource> source, Expression<Func<TSource, decimal>> selector, CancellationToken token)

Parameters

source IQueryable<TSource>

A sequence of values of type TSource.

selector Expression<Func<TSource, decimal>>

A projection function to apply to each element.

token CancellationToken

Returns

Task<decimal>

A task that represents the asynchronous operation. The task result contains the sum of the projected values..

Type Parameters

TSource

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.

Exceptions

ArgumentNullException

source or selector is null.

OperationCanceledException

If the CancellationToken is canceled.

SumAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource, double>>, CancellationToken)

Asynchronously computes the sum of the sequence of values that is obtained by invoking a projection function on each element of the input sequence.

public Task<double> SumAsync<TSource>(IQueryable<TSource> source, Expression<Func<TSource, double>> selector, CancellationToken token)

Parameters

source IQueryable<TSource>

A sequence of values of type TSource.

selector Expression<Func<TSource, double>>

A projection function to apply to each element.

token CancellationToken

Returns

Task<double>

A task that represents the asynchronous operation. The task result contains the sum of the projected values..

Type Parameters

TSource

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.

Exceptions

ArgumentNullException

source or selector is null.

OperationCanceledException

If the CancellationToken is canceled.

SumAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource, int>>, CancellationToken)

Asynchronously computes the sum of the sequence of values that is obtained by invoking a projection function on each element of the input sequence.

public Task<int> SumAsync<TSource>(IQueryable<TSource> source, Expression<Func<TSource, int>> selector, CancellationToken token)

Parameters

source IQueryable<TSource>

A sequence of values of type TSource.

selector Expression<Func<TSource, int>>

A projection function to apply to each element.

token CancellationToken

Returns

Task<int>

A task that represents the asynchronous operation. The task result contains the sum of the projected values..

Type Parameters

TSource

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.

Exceptions

ArgumentNullException

source or selector is null.

OperationCanceledException

If the CancellationToken is canceled.

SumAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource, long>>, CancellationToken)

Asynchronously computes the sum of the sequence of values that is obtained by invoking a projection function on each element of the input sequence.

public Task<long> SumAsync<TSource>(IQueryable<TSource> source, Expression<Func<TSource, long>> selector, CancellationToken token)

Parameters

source IQueryable<TSource>

A sequence of values of type TSource.

selector Expression<Func<TSource, long>>

A projection function to apply to each element.

token CancellationToken

Returns

Task<long>

A task that represents the asynchronous operation. The task result contains the sum of the projected values..

Type Parameters

TSource

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.

Exceptions

ArgumentNullException

source or selector is null.

OperationCanceledException

If the CancellationToken is canceled.

SumAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource, decimal?>>, CancellationToken)

Asynchronously computes the sum of the sequence of values that is obtained by invoking a projection function on each element of the input sequence.

public Task<decimal?> SumAsync<TSource>(IQueryable<TSource> source, Expression<Func<TSource, decimal?>> selector, CancellationToken token)

Parameters

source IQueryable<TSource>

A sequence of values of type TSource.

selector Expression<Func<TSource, decimal?>>

A projection function to apply to each element.

token CancellationToken

Returns

Task<decimal?>

A task that represents the asynchronous operation. The task result contains the sum of the projected values..

Type Parameters

TSource

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.

Exceptions

ArgumentNullException

source or selector is null.

OperationCanceledException

If the CancellationToken is canceled.

SumAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource, double?>>, CancellationToken)

Asynchronously computes the sum of the sequence of values that is obtained by invoking a projection function on each element of the input sequence.

public Task<double?> SumAsync<TSource>(IQueryable<TSource> source, Expression<Func<TSource, double?>> selector, CancellationToken token)

Parameters

source IQueryable<TSource>

A sequence of values of type TSource.

selector Expression<Func<TSource, double?>>

A projection function to apply to each element.

token CancellationToken

Returns

Task<double?>

A task that represents the asynchronous operation. The task result contains the sum of the projected values..

Type Parameters

TSource

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.

Exceptions

ArgumentNullException

source or selector is null.

OperationCanceledException

If the CancellationToken is canceled.

SumAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource, int?>>, CancellationToken)

Asynchronously computes the sum of the sequence of values that is obtained by invoking a projection function on each element of the input sequence.

public Task<int?> SumAsync<TSource>(IQueryable<TSource> source, Expression<Func<TSource, int?>> selector, CancellationToken token)

Parameters

source IQueryable<TSource>

A sequence of values of type TSource.

selector Expression<Func<TSource, int?>>

A projection function to apply to each element.

token CancellationToken

Returns

Task<int?>

A task that represents the asynchronous operation. The task result contains the sum of the projected values..

Type Parameters

TSource

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.

Exceptions

ArgumentNullException

source or selector is null.

OperationCanceledException

If the CancellationToken is canceled.

SumAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource, long?>>, CancellationToken)

Asynchronously computes the sum of the sequence of values that is obtained by invoking a projection function on each element of the input sequence.

public Task<long?> SumAsync<TSource>(IQueryable<TSource> source, Expression<Func<TSource, long?>> selector, CancellationToken token)

Parameters

source IQueryable<TSource>

A sequence of values of type TSource.

selector Expression<Func<TSource, long?>>

A projection function to apply to each element.

token CancellationToken

Returns

Task<long?>

A task that represents the asynchronous operation. The task result contains the sum of the projected values..

Type Parameters

TSource

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.

Exceptions

ArgumentNullException

source or selector is null.

OperationCanceledException

If the CancellationToken is canceled.

SumAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource, float?>>, CancellationToken)

Asynchronously computes the sum of the sequence of values that is obtained by invoking a projection function on each element of the input sequence.

public Task<float?> SumAsync<TSource>(IQueryable<TSource> source, Expression<Func<TSource, float?>> selector, CancellationToken token)

Parameters

source IQueryable<TSource>

A sequence of values of type TSource.

selector Expression<Func<TSource, float?>>

A projection function to apply to each element.

token CancellationToken

Returns

Task<float?>

A task that represents the asynchronous operation. The task result contains the sum of the projected values..

Type Parameters

TSource

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.

Exceptions

ArgumentNullException

source or selector is null.

OperationCanceledException

If the CancellationToken is canceled.

SumAsync<TSource>(IQueryable<TSource>, Expression<Func<TSource, float>>, CancellationToken)

Asynchronously computes the sum of the sequence of values that is obtained by invoking a projection function on each element of the input sequence.

public Task<float> SumAsync<TSource>(IQueryable<TSource> source, Expression<Func<TSource, float>> selector, CancellationToken token)

Parameters

source IQueryable<TSource>

A sequence of values of type TSource.

selector Expression<Func<TSource, float>>

A projection function to apply to each element.

token CancellationToken

Returns

Task<float>

A task that represents the asynchronous operation. The task result contains the sum of the projected values..

Type Parameters

TSource

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.

Exceptions

ArgumentNullException

source or selector is null.

OperationCanceledException

If the CancellationToken is canceled.

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

Asynchronously creates an array from an IQueryable<T> by enumerating it asynchronously.

public Task<TSource[]> ToArrayAsync<TSource>(IQueryable<TSource> source, CancellationToken token)

Parameters

source IQueryable<TSource>

An IQueryable<T> to create an array from.

token CancellationToken

Returns

Task<TSource[]>

A task that represents the asynchronous operation. The task result contains an array that contains elements from the input sequence.

Type Parameters

TSource

The type of the elements of source.

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.

Exceptions

ArgumentNullException

source is null.

OperationCanceledException

If the CancellationToken is canceled.

ToDictionaryAsync<TSource, TKey>(IQueryable<TSource>, Func<TSource, TKey>, IEqualityComparer<TKey>, CancellationToken)

Creates a Dictionary<TKey, TValue> from an IQueryable<T> by enumerating it asynchronously according to a specified key selector function and a comparer.

public Task<Dictionary<TKey, TSource>> ToDictionaryAsync<TSource, TKey>(IQueryable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer, CancellationToken token) where TKey : notnull

Parameters

source IQueryable<TSource>

An IQueryable<T> to create a Dictionary<TKey, TValue> from.

keySelector Func<TSource, TKey>

A function to extract a key from each element.

comparer IEqualityComparer<TKey>

An IEqualityComparer<T> to compare keys.

token CancellationToken

Returns

Task<Dictionary<TKey, TSource>>

A task that represents the asynchronous operation. The task result contains a Dictionary<TKey, TValue> that contains selected keys and values.

Type Parameters

TSource

The type of the elements of source.

TKey

The type of the key returned by keySelector.

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.

Exceptions

ArgumentNullException

source or keySelector is null.

OperationCanceledException

If the CancellationToken is canceled.

ToDictionaryAsync<TSource, TKey>(IQueryable<TSource>, Func<TSource, TKey>, CancellationToken)

Creates a Dictionary<TKey, TValue> from an IQueryable<T> by enumerating it asynchronously according to a specified key selector function.

public Task<Dictionary<TKey, TSource>> ToDictionaryAsync<TSource, TKey>(IQueryable<TSource> source, Func<TSource, TKey> keySelector, CancellationToken token) where TKey : notnull

Parameters

source IQueryable<TSource>

An IQueryable<T> to create a Dictionary<TKey, TValue> from.

keySelector Func<TSource, TKey>

A function to extract a key from each element.

token CancellationToken

Returns

Task<Dictionary<TKey, TSource>>

A task that represents the asynchronous operation. The task result contains a Dictionary<TKey, TValue> that contains selected keys and values.

Type Parameters

TSource

The type of the elements of source.

TKey

The type of the key returned by keySelector.

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.

Exceptions

ArgumentNullException

source or keySelector is null.

OperationCanceledException

If the CancellationToken is canceled.

ToDictionaryAsync<TSource, TKey, TElement>(IQueryable<TSource>, Func<TSource, TKey>, Func<TSource, TElement>, IEqualityComparer<TKey>, CancellationToken)

Creates a Dictionary<TKey, TValue> from an IQueryable<T> by enumerating it asynchronously according to a specified key selector function, a comparer, and an element selector function.

public Task<Dictionary<TKey, TElement>> ToDictionaryAsync<TSource, TKey, TElement>(IQueryable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey> comparer, CancellationToken token) where TKey : notnull

Parameters

source IQueryable<TSource>

An IQueryable<T> to create a Dictionary<TKey, TValue> from.

keySelector Func<TSource, TKey>

A function to extract a key from each element.

elementSelector Func<TSource, TElement>

A transform function to produce a result element value from each element.

comparer IEqualityComparer<TKey>

An IEqualityComparer<T> to compare keys.

token CancellationToken

Returns

Task<Dictionary<TKey, TElement>>

A task that represents the asynchronous operation. The task result contains a Dictionary<TKey, TValue> that contains values of type TElement selected from the input sequence.

Type Parameters

TSource

The type of the elements of source.

TKey

The type of the key returned by keySelector.

TElement

The type of the value returned by elementSelector.

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.

Exceptions

ArgumentNullException

source or keySelector or elementSelector is null.

OperationCanceledException

If the CancellationToken is canceled.

ToDictionaryAsync<TSource, TKey, TElement>(IQueryable<TSource>, Func<TSource, TKey>, Func<TSource, TElement>, CancellationToken)

Creates a Dictionary<TKey, TValue> from an IQueryable<T> by enumerating it asynchronously according to a specified key selector and an element selector function.

public Task<Dictionary<TKey, TElement>> ToDictionaryAsync<TSource, TKey, TElement>(IQueryable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, CancellationToken token) where TKey : notnull

Parameters

source IQueryable<TSource>

An IQueryable<T> to create a Dictionary<TKey, TValue> from.

keySelector Func<TSource, TKey>

A function to extract a key from each element.

elementSelector Func<TSource, TElement>

A transform function to produce a result element value from each element.

token CancellationToken

Returns

Task<Dictionary<TKey, TElement>>

A task that represents the asynchronous operation. The task result contains a Dictionary<TKey, TValue> that contains values of type TElement selected from the input sequence.

Type Parameters

TSource

The type of the elements of source.

TKey

The type of the key returned by keySelector.

TElement

The type of the value returned by elementSelector.

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.

Exceptions

ArgumentNullException

source or keySelector or elementSelector is null.

OperationCanceledException

If the CancellationToken is canceled.

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

Asynchronously creates a List<T> from an IQueryable<T> by enumerating it asynchronously.

public Task<List<TSource>> ToListAsync<TSource>(IQueryable<TSource> source, CancellationToken token)

Parameters

source IQueryable<TSource>

An IQueryable<T> to create a list from.

token CancellationToken

Returns

Task<List<TSource>>

A task that represents the asynchronous operation. The task result contains a List<T> that contains elements from the input sequence.

Type Parameters

TSource

The type of the elements of source.

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.

Exceptions

ArgumentNullException

source is null.

OperationCanceledException

If the CancellationToken is canceled.