Method AsAsyncEnumerable
- Namespace
- Open.Database.Extensions
- Assembly
- Open.Database.Extensions.Core.dll
AsAsyncEnumerable(DbDataReader, CancellationToken)
Asynchronously enumerates the remaining records of the current result set of a DbDataReader as arrays of values; the reader's connection is held while each row is processed.
public static IAsyncEnumerable<object[]> AsAsyncEnumerable(this DbDataReader reader, CancellationToken cancellationToken = default)
Parameters
readerDbDataReaderThe reader to enumerate.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests. The default is None.
Returns
- IAsyncEnumerable<object[]>
An asynchronous enumerable of arrays, one for each record, holding the values of every column.
Remarks
caution
This is not the recommended way to read rows: it holds the
connection while your code runs for each row.
The reader, and the connection under it, stay open for as long as
your code takes per row, added up over all the rows.
In async code that time has no bound: every
await in the loop body can yield, and nothing says
when the loop resumes.
Until it does, the connection is on hold: a pooled connection is
not returned to the pool, and the server may keep its locks and the
open result set.
These members suit work that must happen while the connection is
open, for example a result too large to buffer or a row-by-row
pipeline.
Otherwise use a call that lets go of the connection first:
ToListAsync(CancellationToken)
and
ToArrayAsync(CancellationToken)
buffer the rows and release the connection
(call .Map<T>() first), and
ToPooledStream(CancellationToken)
streams them to a consumer without holding it
(the producer is unbounded: it reads without waiting for the
consumer and frees the connection while the consumer takes its
time, and the rows wait in memory until the consumer takes them;
dispose the enumerator, as await
foreach does).
The same holds when you pass in a reader you opened yourself: the connection under it is held.
DBNull values are retained.
A canceled token ends the enumeration without an exception, and rows already yielded stay yielded.
Exceptions
- ArgumentNullException
readeris null.
AsAsyncEnumerable(DbDataReader, ArrayPool<object>?, CancellationToken)
Asynchronously enumerates the remaining records of the current result set of a DbDataReader as arrays of values; the reader's connection is held while each row is processed.
public static IAsyncEnumerable<object[]> AsAsyncEnumerable(this DbDataReader reader, ArrayPool<object>? arrayPool, CancellationToken cancellationToken = default)
Parameters
readerDbDataReaderThe reader to enumerate.
arrayPoolArrayPool<object>The pool to rent the row arrays from, or null to allocate them.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests. The default is None.
Returns
- IAsyncEnumerable<object[]>
An asynchronous enumerable of arrays, one for each record, holding the values of every column.
Remarks
caution
This is not the recommended way to read rows: it holds the
connection while your code runs for each row.
The reader, and the connection under it, stay open for as long as
your code takes per row, added up over all the rows.
In async code that time has no bound: every
await in the loop body can yield, and nothing says
when the loop resumes.
Until it does, the connection is on hold: a pooled connection is
not returned to the pool, and the server may keep its locks and the
open result set.
These members suit work that must happen while the connection is
open, for example a result too large to buffer or a row-by-row
pipeline.
Otherwise use a call that lets go of the connection first:
ToListAsync(CancellationToken)
and
ToArrayAsync(CancellationToken)
buffer the rows and release the connection
(call .Map<T>() first), and
ToPooledStream(CancellationToken)
streams them to a consumer without holding it
(the producer is unbounded: it reads without waiting for the
consumer and frees the connection while the consumer takes its
time, and the rows wait in memory until the consumer takes them;
dispose the enumerator, as await
foreach does).
The same holds when you pass in a reader you opened yourself: the connection under it is held.
DBNull values are retained.
When arrayPool is not null, each
row array is rented from it, can be longer than the number of values,
and is yielded to the caller, who is responsible for returning it to the
pool.
A canceled token ends the enumeration without an exception, and rows already yielded stay yielded.
Exceptions
- ArgumentNullException
readeris null.
AsAsyncEnumerable(DbDataReader, IEnumerable<int>, CancellationToken)
Asynchronously enumerates the remaining records of the current result set of a DbDataReader as arrays of values; the reader's connection is held while each row is processed.
public static IAsyncEnumerable<object[]> AsAsyncEnumerable(this DbDataReader reader, IEnumerable<int> ordinals, CancellationToken cancellationToken = default)
Parameters
readerDbDataReaderThe reader to enumerate.
ordinalsIEnumerable<int>The limited set of ordinals to include. If none are specified, the returned arrays are empty.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests. The default is None.
Returns
- IAsyncEnumerable<object[]>
An asynchronous enumerable of arrays, one for each record, holding the values of the requested ordinals.
Remarks
caution
This is not the recommended way to read rows: it holds the
connection while your code runs for each row.
The reader, and the connection under it, stay open for as long as
your code takes per row, added up over all the rows.
In async code that time has no bound: every
await in the loop body can yield, and nothing says
when the loop resumes.
Until it does, the connection is on hold: a pooled connection is
not returned to the pool, and the server may keep its locks and the
open result set.
These members suit work that must happen while the connection is
open, for example a result too large to buffer or a row-by-row
pipeline.
Otherwise use a call that lets go of the connection first:
ToListAsync(CancellationToken)
and
ToArrayAsync(CancellationToken)
buffer the rows and release the connection
(call .Map<T>() first), and
ToPooledStream(CancellationToken)
streams them to a consumer without holding it
(the producer is unbounded: it reads without waiting for the
consumer and frees the connection while the consumer takes its
time, and the rows wait in memory until the consumer takes them;
dispose the enumerator, as await
foreach does).
The same holds when you pass in a reader you opened yourself: the connection under it is held.
DBNull values are retained.
A canceled token ends the enumeration without an exception, and rows already yielded stay yielded.
Exceptions
- ArgumentNullException
readerorordinalsis null.
AsAsyncEnumerable(DbDataReader, IEnumerable<int>, ArrayPool<object>?, CancellationToken)
Asynchronously enumerates the remaining records of the current result set of a DbDataReader as arrays of values; the reader's connection is held while each row is processed.
public static IAsyncEnumerable<object[]> AsAsyncEnumerable(this DbDataReader reader, IEnumerable<int> ordinals, ArrayPool<object>? arrayPool, CancellationToken cancellationToken = default)
Parameters
readerDbDataReaderThe reader to enumerate.
ordinalsIEnumerable<int>The limited set of ordinals to include. If none are specified, the returned arrays are empty.
arrayPoolArrayPool<object>The pool to rent the row arrays from, or null to allocate them.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests. The default is None.
Returns
- IAsyncEnumerable<object[]>
An asynchronous enumerable of arrays, one for each record, holding the values of the requested ordinals.
Remarks
caution
This is not the recommended way to read rows: it holds the
connection while your code runs for each row.
The reader, and the connection under it, stay open for as long as
your code takes per row, added up over all the rows.
In async code that time has no bound: every
await in the loop body can yield, and nothing says
when the loop resumes.
Until it does, the connection is on hold: a pooled connection is
not returned to the pool, and the server may keep its locks and the
open result set.
These members suit work that must happen while the connection is
open, for example a result too large to buffer or a row-by-row
pipeline.
Otherwise use a call that lets go of the connection first:
ToListAsync(CancellationToken)
and
ToArrayAsync(CancellationToken)
buffer the rows and release the connection
(call .Map<T>() first), and
ToPooledStream(CancellationToken)
streams them to a consumer without holding it
(the producer is unbounded: it reads without waiting for the
consumer and frees the connection while the consumer takes its
time, and the rows wait in memory until the consumer takes them;
dispose the enumerator, as await
foreach does).
The same holds when you pass in a reader you opened yourself: the connection under it is held.
DBNull values are retained.
When arrayPool is not null, each
row array is rented from it, can be longer than the number of values,
and is yielded to the caller, who is responsible for returning it to the
pool.
A canceled token ends the enumeration without an exception, and rows already yielded stay yielded.
Exceptions
- ArgumentNullException
readerorordinalsis null.