Table of Contents

Class EFForEFExtensions

Namespace
LinqToDB.EntityFrameworkCore
Assembly
linq2db.EntityFrameworkCore.dll

Provides conflict-less mappings to EntityFrameworkQueryableExtensions extensions.

public static class EFForEFExtensions
Inheritance
EFForEFExtensions

Methods

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

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

public static Task<bool> AllAsyncEF<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate, CancellationToken cancellationToken = default)

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.

cancellationToken CancellationToken

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

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.

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

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

public static Task<bool> AnyAsyncEF<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate, CancellationToken cancellationToken = default)

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.

cancellationToken CancellationToken

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

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.

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

Asynchronously determines whether a sequence contains any elements.

public static Task<bool> AnyAsyncEF<TSource>(this IQueryable<TSource> source, CancellationToken cancellationToken = default)

Parameters

source IQueryable<TSource>

An IQueryable<T> to check for being empty.

cancellationToken CancellationToken

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

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.

AverageAsyncEF(IQueryable<decimal>, CancellationToken)

Asynchronously computes the average of a sequence of values.

public static Task<decimal> AverageAsyncEF(this IQueryable<decimal> source, CancellationToken cancellationToken = default)

Parameters

source IQueryable<decimal>

A sequence of values to calculate the average of.

cancellationToken CancellationToken

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

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.

AverageAsyncEF(IQueryable<double>, CancellationToken)

Asynchronously computes the average of a sequence of values.

public static Task<double> AverageAsyncEF(this IQueryable<double> source, CancellationToken cancellationToken = default)

Parameters

source IQueryable<double>

A sequence of values to calculate the average of.

cancellationToken CancellationToken

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

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.

AverageAsyncEF(IQueryable<int>, CancellationToken)

Asynchronously computes the average of a sequence of values.

public static Task<double> AverageAsyncEF(this IQueryable<int> source, CancellationToken cancellationToken = default)

Parameters

source IQueryable<int>

A sequence of values to calculate the average of.

cancellationToken CancellationToken

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

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.

AverageAsyncEF(IQueryable<long>, CancellationToken)

Asynchronously computes the average of a sequence of values.

public static Task<double> AverageAsyncEF(this IQueryable<long> source, CancellationToken cancellationToken = default)

Parameters

source IQueryable<long>

A sequence of values to calculate the average of.

cancellationToken CancellationToken

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

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.

AverageAsyncEF(IQueryable<decimal?>, CancellationToken)

Asynchronously computes the average of a sequence of values.

public static Task<decimal?> AverageAsyncEF(this IQueryable<decimal?> source, CancellationToken cancellationToken = default)

Parameters

source IQueryable<decimal?>

A sequence of values to calculate the average of.

cancellationToken CancellationToken

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

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.

AverageAsyncEF(IQueryable<double?>, CancellationToken)

Asynchronously computes the average of a sequence of values.

public static Task<double?> AverageAsyncEF(this IQueryable<double?> source, CancellationToken cancellationToken = default)

Parameters

source IQueryable<double?>

A sequence of values to calculate the average of.

cancellationToken CancellationToken

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

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.

AverageAsyncEF(IQueryable<int?>, CancellationToken)

Asynchronously computes the average of a sequence of values.

public static Task<double?> AverageAsyncEF(this IQueryable<int?> source, CancellationToken cancellationToken = default)

Parameters

source IQueryable<int?>

A sequence of values to calculate the average of.

cancellationToken CancellationToken

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

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.

AverageAsyncEF(IQueryable<long?>, CancellationToken)

Asynchronously computes the average of a sequence of values.

public static Task<double?> AverageAsyncEF(this IQueryable<long?> source, CancellationToken cancellationToken = default)

Parameters

source IQueryable<long?>

A sequence of values to calculate the average of.

cancellationToken CancellationToken

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

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.

AverageAsyncEF(IQueryable<float?>, CancellationToken)

Asynchronously computes the average of a sequence of values.

public static Task<float?> AverageAsyncEF(this IQueryable<float?> source, CancellationToken cancellationToken = default)

Parameters

source IQueryable<float?>

A sequence of values to calculate the average of.

cancellationToken CancellationToken

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

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.

AverageAsyncEF(IQueryable<float>, CancellationToken)

Asynchronously computes the average of a sequence of values.

public static Task<float> AverageAsyncEF(this IQueryable<float> source, CancellationToken cancellationToken = default)

Parameters

source IQueryable<float>

A sequence of values to calculate the average of.

cancellationToken CancellationToken

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

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.

AverageAsyncEF<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 static Task<decimal> AverageAsyncEF<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, decimal>> selector, CancellationToken cancellationToken = default)

Parameters

source IQueryable<TSource>

A sequence of values of type TSource.

selector Expression<Func<TSource, decimal>>

A projection function to apply to each element.

cancellationToken CancellationToken

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

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.

AverageAsyncEF<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 static Task<double> AverageAsyncEF<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, double>> selector, CancellationToken cancellationToken = default)

Parameters

source IQueryable<TSource>

A sequence of values of type TSource.

selector Expression<Func<TSource, double>>

A projection function to apply to each element.

cancellationToken CancellationToken

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

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.

AverageAsyncEF<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 static Task<double> AverageAsyncEF<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, int>> selector, CancellationToken cancellationToken = default)

Parameters

source IQueryable<TSource>

A sequence of values of type TSource.

selector Expression<Func<TSource, int>>

A projection function to apply to each element.

cancellationToken CancellationToken

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

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.

AverageAsyncEF<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 static Task<double> AverageAsyncEF<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, long>> selector, CancellationToken cancellationToken = default)

Parameters

source IQueryable<TSource>

A sequence of values of type TSource.

selector Expression<Func<TSource, long>>

A projection function to apply to each element.

cancellationToken CancellationToken

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

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.

AverageAsyncEF<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 static Task<decimal?> AverageAsyncEF<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, decimal?>> selector, CancellationToken cancellationToken = default)

Parameters

source IQueryable<TSource>

A sequence of values of type TSource.

selector Expression<Func<TSource, decimal?>>

A projection function to apply to each element.

cancellationToken CancellationToken

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

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.

AverageAsyncEF<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 static Task<double?> AverageAsyncEF<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, double?>> selector, CancellationToken cancellationToken = default)

Parameters

source IQueryable<TSource>

A sequence of values of type TSource.

selector Expression<Func<TSource, double?>>

A projection function to apply to each element.

cancellationToken CancellationToken

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

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.

AverageAsyncEF<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 static Task<double?> AverageAsyncEF<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, int?>> selector, CancellationToken cancellationToken = default)

Parameters

source IQueryable<TSource>

A sequence of values of type TSource.

selector Expression<Func<TSource, int?>>

A projection function to apply to each element.

cancellationToken CancellationToken

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

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.

AverageAsyncEF<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 static Task<double?> AverageAsyncEF<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, long?>> selector, CancellationToken cancellationToken = default)

Parameters

source IQueryable<TSource>

A sequence of values of type TSource.

selector Expression<Func<TSource, long?>>

A projection function to apply to each element.

cancellationToken CancellationToken

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

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.

AverageAsyncEF<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 static Task<float?> AverageAsyncEF<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, float?>> selector, CancellationToken cancellationToken = default)

Parameters

source IQueryable<TSource>

A sequence of values of type TSource.

selector Expression<Func<TSource, float?>>

A projection function to apply to each element.

cancellationToken CancellationToken

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

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.

AverageAsyncEF<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 static Task<float> AverageAsyncEF<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, float>> selector, CancellationToken cancellationToken = default)

Parameters

source IQueryable<TSource>

A sequence of values of type TSource.

selector Expression<Func<TSource, float>>

A projection function to apply to each element.

cancellationToken CancellationToken

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

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.

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

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

public static Task<bool> ContainsAsyncEF<TSource>(this IQueryable<TSource> source, TSource item, CancellationToken cancellationToken = default)

Parameters

source IQueryable<TSource>

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

item TSource

The object to locate in the sequence.

cancellationToken CancellationToken

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

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.

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

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

public static Task<int> CountAsyncEF<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate, CancellationToken cancellationToken = default)

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.

cancellationToken CancellationToken

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

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.

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

Asynchronously returns the number of elements in a sequence.

public static Task<int> CountAsyncEF<TSource>(this IQueryable<TSource> source, CancellationToken cancellationToken = default)

Parameters

source IQueryable<TSource>

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

cancellationToken CancellationToken

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

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.

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

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

public static Task<TSource> FirstAsyncEF<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate, CancellationToken cancellationToken = default)

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.

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 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.

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

Asynchronously returns the first element of a sequence.

public static Task<TSource> FirstAsyncEF<TSource>(this IQueryable<TSource> source, CancellationToken token = default)

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.

FirstOrDefaultAsyncEF<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 static Task<TSource?> FirstOrDefaultAsyncEF<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate, CancellationToken cancellationToken = default)

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.

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 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.

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

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

public static Task<TSource?> FirstOrDefaultAsyncEF<TSource>(this IQueryable<TSource> source, CancellationToken cancellationToken = default)

Parameters

source IQueryable<TSource>

An IQueryable<T> to return the first 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 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.

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

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

public static Task ForEachAsyncEF<TSource>(this IQueryable<TSource> source, Action<TSource> action, CancellationToken cancellationToken = default)

Parameters

source IQueryable<TSource>

An IQueryable<T> to enumerate.

action Action<TSource>

The action to perform on each element.

cancellationToken CancellationToken

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

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.

LongCountAsyncEF<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 static Task<long> LongCountAsyncEF<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate, CancellationToken cancellationToken = default)

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.

cancellationToken CancellationToken

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

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.

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

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

public static Task<long> LongCountAsyncEF<TSource>(this IQueryable<TSource> source, CancellationToken cancellationToken = default)

Parameters

source IQueryable<TSource>

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

cancellationToken CancellationToken

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

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.

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

Asynchronously returns the maximum value of a sequence.

public static Task<TSource> MaxAsyncEF<TSource>(this IQueryable<TSource> source, CancellationToken cancellationToken = default)

Parameters

source IQueryable<TSource>

An IQueryable<T> that contains the elements to determine the maximum 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 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.

MaxAsyncEF<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 static Task<TResult> MaxAsyncEF<TSource, TResult>(this IQueryable<TSource> source, Expression<Func<TSource, TResult>> selector, CancellationToken cancellationToken = default)

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.

cancellationToken CancellationToken

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

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.

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

Asynchronously returns the minimum value of a sequence.

public static Task<TSource> MinAsyncEF<TSource>(this IQueryable<TSource> source, CancellationToken cancellationToken = default)

Parameters

source IQueryable<TSource>

An IQueryable<T> that contains the elements to determine the minimum 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 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.

MinAsyncEF<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 static Task<TResult> MinAsyncEF<TSource, TResult>(this IQueryable<TSource> source, Expression<Func<TSource, TResult>> selector, CancellationToken cancellationToken = default)

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.

cancellationToken CancellationToken

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

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.

SingleAsyncEF<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 static Task<TSource> SingleAsyncEF<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate, CancellationToken cancellationToken = default)

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.

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 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.

SingleAsyncEF<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 static Task<TSource> SingleAsyncEF<TSource>(this IQueryable<TSource> source, CancellationToken cancellationToken = default)

Parameters

source IQueryable<TSource>

An IQueryable<T> to return the single 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 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.

SingleOrDefaultAsyncEF<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 static Task<TSource?> SingleOrDefaultAsyncEF<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, bool>> predicate, CancellationToken cancellationToken = default)

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.

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 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.

SingleOrDefaultAsyncEF<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 static Task<TSource?> SingleOrDefaultAsyncEF<TSource>(this IQueryable<TSource> source, CancellationToken cancellationToken = default)

Parameters

source IQueryable<TSource>

An IQueryable<T> to return the single 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 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.

SumAsyncEF(IQueryable<decimal>, CancellationToken)

Asynchronously computes the sum of a sequence of values.

public static Task<decimal> SumAsyncEF(this IQueryable<decimal> source, CancellationToken cancellationToken = default)

Parameters

source IQueryable<decimal>

A sequence of values to calculate the sum of.

cancellationToken CancellationToken

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

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.

SumAsyncEF(IQueryable<double>, CancellationToken)

Asynchronously computes the sum of a sequence of values.

public static Task<double> SumAsyncEF(this IQueryable<double> source, CancellationToken cancellationToken = default)

Parameters

source IQueryable<double>

A sequence of values to calculate the sum of.

cancellationToken CancellationToken

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

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.

SumAsyncEF(IQueryable<int>, CancellationToken)

Asynchronously computes the sum of a sequence of values.

public static Task<int> SumAsyncEF(this IQueryable<int> source, CancellationToken cancellationToken = default)

Parameters

source IQueryable<int>

A sequence of values to calculate the sum of.

cancellationToken CancellationToken

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

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.

SumAsyncEF(IQueryable<long>, CancellationToken)

Asynchronously computes the sum of a sequence of values.

public static Task<long> SumAsyncEF(this IQueryable<long> source, CancellationToken cancellationToken = default)

Parameters

source IQueryable<long>

A sequence of values to calculate the sum of.

cancellationToken CancellationToken

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

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.

SumAsyncEF(IQueryable<decimal?>, CancellationToken)

Asynchronously computes the sum of a sequence of values.

public static Task<decimal?> SumAsyncEF(this IQueryable<decimal?> source, CancellationToken cancellationToken = default)

Parameters

source IQueryable<decimal?>

A sequence of values to calculate the sum of.

cancellationToken CancellationToken

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

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.

SumAsyncEF(IQueryable<double?>, CancellationToken)

Asynchronously computes the sum of a sequence of values.

public static Task<double?> SumAsyncEF(this IQueryable<double?> source, CancellationToken cancellationToken = default)

Parameters

source IQueryable<double?>

A sequence of values to calculate the sum of.

cancellationToken CancellationToken

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

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.

SumAsyncEF(IQueryable<int?>, CancellationToken)

Asynchronously computes the sum of a sequence of values.

public static Task<int?> SumAsyncEF(this IQueryable<int?> source, CancellationToken cancellationToken = default)

Parameters

source IQueryable<int?>

A sequence of values to calculate the sum of.

cancellationToken CancellationToken

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

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.

SumAsyncEF(IQueryable<long?>, CancellationToken)

Asynchronously computes the sum of a sequence of values.

public static Task<long?> SumAsyncEF(this IQueryable<long?> source, CancellationToken cancellationToken = default)

Parameters

source IQueryable<long?>

A sequence of values to calculate the sum of.

cancellationToken CancellationToken

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

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.

SumAsyncEF(IQueryable<float?>, CancellationToken)

Asynchronously computes the sum of a sequence of values.

public static Task<float?> SumAsyncEF(this IQueryable<float?> source, CancellationToken cancellationToken = default)

Parameters

source IQueryable<float?>

A sequence of values to calculate the sum of.

cancellationToken CancellationToken

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

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.

SumAsyncEF(IQueryable<float>, CancellationToken)

Asynchronously computes the sum of a sequence of values.

public static Task<float> SumAsyncEF(this IQueryable<float> source, CancellationToken cancellationToken = default)

Parameters

source IQueryable<float>

A sequence of values to calculate the sum of.

cancellationToken CancellationToken

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

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.

SumAsyncEF<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 static Task<decimal> SumAsyncEF<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, decimal>> selector, CancellationToken cancellationToken = default)

Parameters

source IQueryable<TSource>

A sequence of values of type TSource.

selector Expression<Func<TSource, decimal>>

A projection function to apply to each element.

cancellationToken CancellationToken

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

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.

SumAsyncEF<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 static Task<double> SumAsyncEF<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, double>> selector, CancellationToken cancellationToken = default)

Parameters

source IQueryable<TSource>

A sequence of values of type TSource.

selector Expression<Func<TSource, double>>

A projection function to apply to each element.

cancellationToken CancellationToken

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

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.

SumAsyncEF<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 static Task<int> SumAsyncEF<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, int>> selector, CancellationToken cancellationToken = default)

Parameters

source IQueryable<TSource>

A sequence of values of type TSource.

selector Expression<Func<TSource, int>>

A projection function to apply to each element.

cancellationToken CancellationToken

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

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.

SumAsyncEF<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 static Task<long> SumAsyncEF<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, long>> selector, CancellationToken cancellationToken = default)

Parameters

source IQueryable<TSource>

A sequence of values of type TSource.

selector Expression<Func<TSource, long>>

A projection function to apply to each element.

cancellationToken CancellationToken

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

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.

SumAsyncEF<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 static Task<decimal?> SumAsyncEF<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, decimal?>> selector, CancellationToken cancellationToken = default)

Parameters

source IQueryable<TSource>

A sequence of values of type TSource.

selector Expression<Func<TSource, decimal?>>

A projection function to apply to each element.

cancellationToken CancellationToken

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

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.

SumAsyncEF<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 static Task<double?> SumAsyncEF<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, double?>> selector, CancellationToken cancellationToken = default)

Parameters

source IQueryable<TSource>

A sequence of values of type TSource.

selector Expression<Func<TSource, double?>>

A projection function to apply to each element.

cancellationToken CancellationToken

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

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.

SumAsyncEF<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 static Task<int?> SumAsyncEF<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, int?>> selector, CancellationToken cancellationToken = default)

Parameters

source IQueryable<TSource>

A sequence of values of type TSource.

selector Expression<Func<TSource, int?>>

A projection function to apply to each element.

cancellationToken CancellationToken

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

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.

SumAsyncEF<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 static Task<long?> SumAsyncEF<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, long?>> selector, CancellationToken cancellationToken = default)

Parameters

source IQueryable<TSource>

A sequence of values of type TSource.

selector Expression<Func<TSource, long?>>

A projection function to apply to each element.

cancellationToken CancellationToken

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

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.

SumAsyncEF<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 static Task<float?> SumAsyncEF<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, float?>> selector, CancellationToken cancellationToken = default)

Parameters

source IQueryable<TSource>

A sequence of values of type TSource.

selector Expression<Func<TSource, float?>>

A projection function to apply to each element.

cancellationToken CancellationToken

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

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.

SumAsyncEF<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 static Task<float> SumAsyncEF<TSource>(this IQueryable<TSource> source, Expression<Func<TSource, float>> selector, CancellationToken cancellationToken = default)

Parameters

source IQueryable<TSource>

A sequence of values of type TSource.

selector Expression<Func<TSource, float>>

A projection function to apply to each element.

cancellationToken CancellationToken

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

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.

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

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

public static Task<TSource[]> ToArrayAsyncEF<TSource>(this IQueryable<TSource> source, CancellationToken cancellationToken = default)

Parameters

source IQueryable<TSource>

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

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 a Dictionary<TKey, TValue> that contains selected keys and 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 keySelector is null.

OperationCanceledException

If the CancellationToken is canceled.

ToDictionaryAsyncEF<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 and a comparer.

public static Task<Dictionary<TKey, TSource>> ToDictionaryAsyncEF<TSource, TKey>(this IQueryable<TSource> source, Func<TSource, TKey> keySelector, CancellationToken cancellationToken = default) 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.

cancellationToken CancellationToken

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

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.

ToDictionaryAsyncEF<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 static Task<Dictionary<TKey, TElement>> ToDictionaryAsyncEF<TSource, TKey, TElement>(this IQueryable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken = default) 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.

cancellationToken CancellationToken

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

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.

ToDictionaryAsyncEF<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 static Task<Dictionary<TKey, TElement>> ToDictionaryAsyncEF<TSource, TKey, TElement>(this IQueryable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, CancellationToken cancellationToken = default) 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.

cancellationToken CancellationToken

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

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.

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

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

public static Task<List<TSource>> ToListAsyncEF<TSource>(this IQueryable<TSource> source, CancellationToken cancellationToken = default)

Parameters

source IQueryable<TSource>

An IQueryable<T> to create a list from.

cancellationToken CancellationToken

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

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.