net10.0, netstandard2.1, netstandard2.0

public class CsvQuery<T> : IOrderedQueryable<T>, IEnumerable<T>, IEnumerable, IOrderedQueryable, IQueryable, IQueryable<T>, ICsvRoot, IAsyncSource<T>

net47

public class CsvQuery<T> : IOrderedQueryable<T>, IQueryable<T>, IEnumerable<T>, IEnumerable, IQueryable, IOrderedQueryable, ICsvRoot, IAsyncSource<T>
Namespace
CsvHelper.Linq
Assembly
CsvHelper.Linq.dll
Implements
IOrderedQueryable<T>, IEnumerable<T>, IEnumerable, IOrderedQueryable, IQueryable, IQueryable<T>, ICsvRoot, IAsyncSource<T>
Builds
net10.0 netstandard2.1 netstandard2.0 net47

Remarks

Any LINQ operator can be used. CsvQueryable.Explain tells what a query pushes into the reader.

await foreach over a CsvQuery<T> reads the CSV asynchronously (GetAsyncEnumerator); CsvQueryable.AsCsvAsync does the same for the IQueryable<T> that LINQ operators return, and has asynchronous versions of ToList, Count, First and the others. The queries that operators return also implement IAsyncEnumerable<T>, for code that looks for it, such as the ToListAsync of Entity Framework Core. This class does not, so that the LINQ operators of Queryable and of .NET 10's AsyncEnumerable are not both candidates for a query typed as it.

Properties

Expression

Added in v34.0.0
public Expression Expression { get; }

The query: a constant holding the source for the query of all its records, else the operators applied to it.

Property value

View source

Methods

Explain()

Added in v34.0.0
public CsvQueryPlan Explain()

Tells how the query runs without running it: which members of the records it reads, which operators the CSV reader runs, and what it asks other providers for.

Returns

CsvQueryPlan
The plan of the query.

View source

public IAsyncEnumerator<T> GetAsyncEnumerator(CancellationToken cancellationToken = default)

Runs the query and reads its results as they are enumerated, reading the CSV asynchronously. When the query has operators that the CSV reader does not run itself, the records it reads are buffered first and the rest of the query runs on them; otherwise the results stream.

Parameters

cancellationTokenCancellationToken
Cancels the reading.

Returns

IAsyncEnumerator<T>
An enumerator of the results; disposing it closes the sources it opened.

View source

ToString()

Added in v34.0.0
public override string ToString()

The query, as text.

Returns

string
The source and the operators, such as file 'orders.csv'.Where(o => (o.Total > 100)).

View source