Method BindColumnAsync
- Namespace
- YndigoBlue.Velocity.Engine
- Assembly
- YndigoBlue.Velocity.dll
BindColumnAsync<T>(string, CancellationToken)
Asynchronous counterpart to BindColumn<T>(string). Binds a single column from query results to a typed async sequence by column name.
public IAsyncEnumerable<T> BindColumnAsync<T>(string columnName, CancellationToken cancellationToken = default)
Parameters
columnNamestringThe name of the column to bind.
cancellationTokenCancellationTokenA token to cancel the underlying
ReadAsynccalls.
Returns
- IAsyncEnumerable<T>
A lazy IAsyncEnumerable<T> that streams typed values from the specified column one row at a time.
Type Parameters
TThe type to bind the column values to.
Examples
await using (ResultReader reader = await manager.SearchAsync(query))
{
// Extract just the order_total column as decimals
await foreach (decimal total in reader.BindColumnAsync<decimal>("order_total"))
{
Console.WriteLine($"Order total: {total:C}");
}
}
Remarks
Returns a lazy async sequence backed by yield return. Rows are not fetched until the returned
sequence is iterated with await foreach, and each iteration issues a non-blocking
ReadAsync(CancellationToken) call against the live database reader.
The sequence must be fully consumed inside the enclosing await using (ResultReader ...) block;
iterating after the reader has been disposed will throw.
BindColumnAsync<T>(int, CancellationToken)
Asynchronous counterpart to BindColumn<T>(int). Binds a single column from query results to a typed async sequence by column index.
public IAsyncEnumerable<T> BindColumnAsync<T>(int columnIndex, CancellationToken cancellationToken = default)
Parameters
columnIndexintThe zero-based index of the column to bind.
cancellationTokenCancellationTokenA token to cancel the underlying
ReadAsynccalls.
Returns
- IAsyncEnumerable<T>
A lazy IAsyncEnumerable<T> that streams typed values from the specified column one row at a time.
Type Parameters
TThe type to bind the column values to.
Remarks
Returns a lazy async sequence backed by yield return. The returned sequence reads from the live
database reader and must be iterated inside the enclosing await using (ResultReader ...) block.
Iterating after the reader has been disposed will throw.
BindColumnAsync<T>(CancellationToken)
Asynchronous counterpart to BindColumn<T>(). Binds the first column from query results to a typed async sequence.
public IAsyncEnumerable<T> BindColumnAsync<T>(CancellationToken cancellationToken = default)
Parameters
cancellationTokenCancellationTokenA token to cancel the underlying
ReadAsynccalls.
Returns
- IAsyncEnumerable<T>
A lazy IAsyncEnumerable<T> that streams typed values from the first column one row at a time.
Type Parameters
TThe type to bind the column values to.
Remarks
Returns a lazy async sequence backed by yield return. The returned sequence reads from the live
database reader and must be iterated inside the enclosing await using (ResultReader ...) block.
Iterating after the reader has been disposed will throw.