public sealed class CsvAsyncQuery<T> : IAsyncEnumerable<T>
Namespace
CsvHelper.Linq
Assembly
CsvHelper.Linq.dll
Implements
IAsyncEnumerable<T>
Builds
net10.0 netstandard2.1 netstandard2.0 net47

Remarks

Its operators are instance methods, so they are chosen over the extension methods of the same names that Entity Framework Core and .NET 10's AsyncEnumerable have.

When the CSV reader runs the whole query (filters, skips and the operators that read the records it returns, such as Select and Take), the records stream; otherwise the records that the reader returns are read into memory first, and the rest of the query runs on them.

Methods

public Task<bool> AllAsync(Expression<Func<T, bool>> predicate, CancellationToken cancellationToken = default)

Whether every result matches a condition; reading stops at the first that does not.

Parameters

predicateExpression<Func<T, bool>>
The condition.
cancellationTokenCancellationToken
Cancels the reading.

Returns

Task<bool>
true when all results match, or there are none.

Exceptions

ArgumentNullException
predicate is null.

View source

public Task<TResult> ExecuteAsync<TResult>(Expression<Func<IQueryable<T>, TResult>> operation, CancellationToken cancellationToken = default)

Runs any other operator that returns a single value, such as q => q.Sum(o => o.Total) or q => q.Max(o => o.Placed), reading the CSV asynchronously.

Type parameters

TResult
The type of the value.

Parameters

operationExpression<Func<IQueryable<T>, TResult>>
The operator, applied to the query.
cancellationTokenCancellationToken
Cancels the reading.

Returns

Task<TResult>
The value.

Exceptions

ArgumentNullException
operation is null.

View source

public Task<T?> FirstOrDefaultAsync(Expression<Func<T, bool>> predicate, CancellationToken cancellationToken = default)

The first result that matches a condition, or the default of T when none does.

Parameters

predicateExpression<Func<T, bool>>
The condition.
cancellationTokenCancellationToken
Cancels the reading.

Returns

Task<T?>
The first result that matches, or the default.

Exceptions

ArgumentNullException
predicate is null.

View source

public Task<T> SingleAsync(Expression<Func<T, bool>> predicate, CancellationToken cancellationToken = default)

The only result that matches a condition.

Parameters

predicateExpression<Func<T, bool>>
The condition.
cancellationTokenCancellationToken
Cancels the reading.

Returns

Task<T>
The only result that matches.

Exceptions

ArgumentNullException
predicate is null.
InvalidOperationException
No result matches, or more than one.

View source

public Task<T?> SingleOrDefaultAsync(Expression<Func<T, bool>> predicate, CancellationToken cancellationToken = default)

The only result that matches a condition, or the default of T when none does.

Parameters

predicateExpression<Func<T, bool>>
The condition.
cancellationTokenCancellationToken
Cancels the reading.

Returns

Task<T?>
The only result that matches, or the default.

Exceptions

ArgumentNullException
predicate is null.
InvalidOperationException
More than one result matches.

View source