Method AsSourceBlock
- Namespace
- Open.Database.Extensions
- Assembly
- Open.Database.Extensions.Dataflow.dll
AsSourceBlock(IDataReader, DataflowBlockOptions?)
Reads an IDataReader to the end, posting each record as an array of values to a new BufferBlock<T>, and returns the block.
public static IReceivableSourceBlock<object[]> AsSourceBlock(this IDataReader reader, DataflowBlockOptions? options = null)
Parameters
readerIDataReaderThe data reader to iterate. The caller owns it: it is not closed or disposed here, and it must stay open until the operation completes.
optionsDataflowBlockOptionsOptions for the returned block, such as its bounded capacity, or null for the defaults.
Returns
- IReceivableSourceBlock<object[]>
The block that receives the records. It is completed after the last record has been delivered, or faulted with the exception that ended the reading.
Remarks
This method is synchronous: it returns only after the source has been read to the end (or the block declined a record), so the calling thread is blocked while the database responds. Exceptions from reading propagate to the caller.
Records are posted without waiting for room. With the default unbounded options every record is accepted, but if options sets a bounded capacity, a full block declines the next record, which silently stops the reading early and drops that record. Use the AsSourceBlockAsync overloads for a bounded block, or when the caller should not be blocked.
Exceptions
- ArgumentNullException
readeris null.
AsSourceBlock(IDataReader, ArrayPool<object>, DataflowBlockOptions?)
Reads an IDataReader to the end, posting each record as an array of values rented from an array pool to a new BufferBlock<T>, and returns the block.
public static IReceivableSourceBlock<object[]> AsSourceBlock(this IDataReader reader, ArrayPool<object> arrayPool, DataflowBlockOptions? options = null)
Parameters
readerIDataReaderThe data reader to iterate. The caller owns it: it is not closed or disposed here, and it must stay open until the operation completes.
arrayPoolArrayPool<object>The array pool to rent each record's array from. The consumer of the records is responsible for returning each array to the pool.
optionsDataflowBlockOptionsOptions for the returned block, such as its bounded capacity, or null for the defaults.
Returns
- IReceivableSourceBlock<object[]>
The block that receives the records. It is completed after the last record has been delivered, or faulted with the exception that ended the reading.
Remarks
This method is synchronous: it returns only after the source has been read to the end (or the block declined a record), so the calling thread is blocked while the database responds. Exceptions from reading propagate to the caller.
Records are posted without waiting for room. With the default unbounded options every record is accepted, but if options sets a bounded capacity, a full block declines the next record, which silently stops the reading early and drops that record. Use the AsSourceBlockAsync overloads for a bounded block, or when the caller should not be blocked.
Exceptions
- ArgumentNullException
readeris null.
AsSourceBlock<T>(IDataReader, Func<IDataRecord, T>, DataflowBlockOptions?)
Reads an IDataReader to the end, posting each record after it has been transformed by transform to a new BufferBlock<T>, and returns the block.
public static IReceivableSourceBlock<T> AsSourceBlock<T>(this IDataReader reader, Func<IDataRecord, T> transform, DataflowBlockOptions? options = null)
Parameters
readerIDataReaderThe data reader to iterate. The caller owns it: it is not closed or disposed here, and it must stay open until the operation completes.
transformFunc<IDataRecord, T>The function that transforms each IDataRecord into the item delivered to the block.
optionsDataflowBlockOptionsOptions for the returned block, such as its bounded capacity, or null for the defaults.
Returns
- IReceivableSourceBlock<T>
The block that receives the records. It is completed after the last record has been delivered, or faulted with the exception that ended the reading.
Type Parameters
TThe type of the items delivered to the block: the return type of the transform function.
Remarks
This method is synchronous: it returns only after the source has been read to the end (or the block declined a record), so the calling thread is blocked while the database responds. Exceptions from reading propagate to the caller.
Records are posted without waiting for room. With the default unbounded options every record is accepted, but if options sets a bounded capacity, a full block declines the next record, which silently stops the reading early and drops that record. Use the AsSourceBlockAsync overloads for a bounded block, or when the caller should not be blocked.
Exceptions
- ArgumentNullException
readeris null.
AsSourceBlock<T>(IDataReader, DataflowBlockOptions?)
Reads an IDataReader to the end, posting each record mapped to a new instance of T to a new BufferBlock<T>, and returns the block.
public static IReceivableSourceBlock<T> AsSourceBlock<T>(this IDataReader reader, DataflowBlockOptions? options = null) where T : new()
Parameters
readerIDataReaderThe data reader to iterate. The caller owns it: it is not closed or disposed here, and it must stay open until the operation completes.
optionsDataflowBlockOptionsOptions for the returned block, such as its bounded capacity, or null for the defaults.
Returns
- IReceivableSourceBlock<T>
The block that receives the records. It is completed after the last record has been delivered, or faulted with the exception that ended the reading.
Type Parameters
TThe type each record is mapped to.
Remarks
This method is synchronous: it returns only after the source has been read to the end (or the block declined a record), so the calling thread is blocked while the database responds. Exceptions from reading propagate to the caller.
Records are posted without waiting for room. With the default unbounded options every record is accepted, but if options sets a bounded capacity, a full block declines the next record, which silently stops the reading early and drops that record. Use the AsSourceBlockAsync overloads for a bounded block, or when the caller should not be blocked.
Mapping is done by an internal pipeline, so the last records and the completion of the block can arrive shortly after this method returns.
Exceptions
- ArgumentNullException
readeris null.
AsSourceBlock<T>(IDataReader, IEnumerable<(string Field, string? Column)>, DataflowBlockOptions?)
Reads an IDataReader to the end, posting each record mapped to a new instance of T, using the field-to-column overrides to a new BufferBlock<T>, and returns the block.
public static IReceivableSourceBlock<T> AsSourceBlock<T>(this IDataReader reader, IEnumerable<(string Field, string? Column)> fieldMappingOverrides, DataflowBlockOptions? options = null) where T : new()
Parameters
readerIDataReaderThe data reader to iterate. The caller owns it: it is not closed or disposed here, and it must stay open until the operation completes.
fieldMappingOverridesIEnumerable<(string Field, string Column)>An override map of field names to column names, applied on top of the default name-based mapping.
optionsDataflowBlockOptionsOptions for the returned block, such as its bounded capacity, or null for the defaults.
Returns
- IReceivableSourceBlock<T>
The block that receives the records. It is completed after the last record has been delivered, or faulted with the exception that ended the reading.
Type Parameters
TThe type each record is mapped to.
Remarks
This method is synchronous: it returns only after the source has been read to the end (or the block declined a record), so the calling thread is blocked while the database responds. Exceptions from reading propagate to the caller.
Records are posted without waiting for room. With the default unbounded options every record is accepted, but if options sets a bounded capacity, a full block declines the next record, which silently stops the reading early and drops that record. Use the AsSourceBlockAsync overloads for a bounded block, or when the caller should not be blocked.
Mapping is done by an internal pipeline, so the last records and the completion of the block can arrive shortly after this method returns.
Exceptions
- ArgumentNullException
readeris null.
AsSourceBlock(IDbCommand, DataflowBlockOptions?)
Reads the results of an IDbCommand to the end, posting each record as an array of values to a new BufferBlock<T>, and returns the block.
public static IReceivableSourceBlock<object[]> AsSourceBlock(this IDbCommand command, DataflowBlockOptions? options = null)
Parameters
commandIDbCommandThe command to execute. Its connection is opened if needed and closed again if it was opened here; neither the command nor the connection is disposed.
optionsDataflowBlockOptionsOptions for the returned block, such as its bounded capacity, or null for the defaults.
Returns
- IReceivableSourceBlock<object[]>
The block that receives the records. It is completed after the last record has been delivered, or faulted with the exception that ended the reading.
Remarks
This method is synchronous: it returns only after the source has been read to the end (or the block declined a record), so the calling thread is blocked while the database responds. Exceptions from reading propagate to the caller.
Records are posted without waiting for room. With the default unbounded options every record is accepted, but if options sets a bounded capacity, a full block declines the next record, which silently stops the reading early and drops that record. Use the AsSourceBlockAsync overloads for a bounded block, or when the caller should not be blocked.
Exceptions
- ArgumentNullException
commandis null.
AsSourceBlock(IDbCommand, ArrayPool<object>, DataflowBlockOptions?)
Reads the results of an IDbCommand to the end, posting each record as an array of values rented from an array pool to a new BufferBlock<T>, and returns the block.
public static IReceivableSourceBlock<object[]> AsSourceBlock(this IDbCommand command, ArrayPool<object> arrayPool, DataflowBlockOptions? options = null)
Parameters
commandIDbCommandThe command to execute. Its connection is opened if needed and closed again if it was opened here; neither the command nor the connection is disposed.
arrayPoolArrayPool<object>The array pool to rent each record's array from. The consumer of the records is responsible for returning each array to the pool.
optionsDataflowBlockOptionsOptions for the returned block, such as its bounded capacity, or null for the defaults.
Returns
- IReceivableSourceBlock<object[]>
The block that receives the records. It is completed after the last record has been delivered, or faulted with the exception that ended the reading.
Remarks
This method is synchronous: it returns only after the source has been read to the end (or the block declined a record), so the calling thread is blocked while the database responds. Exceptions from reading propagate to the caller.
Records are posted without waiting for room. With the default unbounded options every record is accepted, but if options sets a bounded capacity, a full block declines the next record, which silently stops the reading early and drops that record. Use the AsSourceBlockAsync overloads for a bounded block, or when the caller should not be blocked.
Exceptions
- ArgumentNullException
commandis null.
AsSourceBlock<T>(IDbCommand, Func<IDataRecord, T>, DataflowBlockOptions?)
Reads the results of an IDbCommand to the end, posting each record after it has been transformed by transform to a new BufferBlock<T>, and returns the block.
public static IReceivableSourceBlock<T> AsSourceBlock<T>(this IDbCommand command, Func<IDataRecord, T> transform, DataflowBlockOptions? options = null)
Parameters
commandIDbCommandThe command to execute. Its connection is opened if needed and closed again if it was opened here; neither the command nor the connection is disposed.
transformFunc<IDataRecord, T>The function that transforms each IDataRecord into the item delivered to the block.
optionsDataflowBlockOptionsOptions for the returned block, such as its bounded capacity, or null for the defaults.
Returns
- IReceivableSourceBlock<T>
The block that receives the records. It is completed after the last record has been delivered, or faulted with the exception that ended the reading.
Type Parameters
TThe type of the items delivered to the block: the return type of the transform function.
Remarks
This method is synchronous: it returns only after the source has been read to the end (or the block declined a record), so the calling thread is blocked while the database responds. Exceptions from reading propagate to the caller.
Records are posted without waiting for room. With the default unbounded options every record is accepted, but if options sets a bounded capacity, a full block declines the next record, which silently stops the reading early and drops that record. Use the AsSourceBlockAsync overloads for a bounded block, or when the caller should not be blocked.
Exceptions
- ArgumentNullException
commandis null.
AsSourceBlock<T>(IDbCommand, DataflowBlockOptions?)
Reads the results of an IDbCommand to the end, posting each record mapped to a new instance of T to a new BufferBlock<T>, and returns the block.
public static IReceivableSourceBlock<T> AsSourceBlock<T>(this IDbCommand command, DataflowBlockOptions? options = null) where T : new()
Parameters
commandIDbCommandThe command to execute. Its connection is opened if needed and closed again if it was opened here; neither the command nor the connection is disposed.
optionsDataflowBlockOptionsOptions for the returned block, such as its bounded capacity, or null for the defaults.
Returns
- IReceivableSourceBlock<T>
The block that receives the records. It is completed after the last record has been delivered, or faulted with the exception that ended the reading.
Type Parameters
TThe type each record is mapped to.
Remarks
This method is synchronous: it returns only after the source has been read to the end (or the block declined a record), so the calling thread is blocked while the database responds. Exceptions from reading propagate to the caller.
Records are posted without waiting for room. With the default unbounded options every record is accepted, but if options sets a bounded capacity, a full block declines the next record, which silently stops the reading early and drops that record. Use the AsSourceBlockAsync overloads for a bounded block, or when the caller should not be blocked.
Mapping is done by an internal pipeline, so the last records and the completion of the block can arrive shortly after this method returns.
Exceptions
- ArgumentNullException
commandis null.
AsSourceBlock<T>(IDbCommand, IEnumerable<(string Field, string? Column)>, DataflowBlockOptions?)
Reads the results of an IDbCommand to the end, posting each record mapped to a new instance of T, using the field-to-column overrides to a new BufferBlock<T>, and returns the block.
public static IReceivableSourceBlock<T> AsSourceBlock<T>(this IDbCommand command, IEnumerable<(string Field, string? Column)> fieldMappingOverrides, DataflowBlockOptions? options = null) where T : new()
Parameters
commandIDbCommandThe command to execute. Its connection is opened if needed and closed again if it was opened here; neither the command nor the connection is disposed.
fieldMappingOverridesIEnumerable<(string Field, string Column)>An override map of field names to column names, applied on top of the default name-based mapping.
optionsDataflowBlockOptionsOptions for the returned block, such as its bounded capacity, or null for the defaults.
Returns
- IReceivableSourceBlock<T>
The block that receives the records. It is completed after the last record has been delivered, or faulted with the exception that ended the reading.
Type Parameters
TThe type each record is mapped to.
Remarks
This method is synchronous: it returns only after the source has been read to the end (or the block declined a record), so the calling thread is blocked while the database responds. Exceptions from reading propagate to the caller.
Records are posted without waiting for room. With the default unbounded options every record is accepted, but if options sets a bounded capacity, a full block declines the next record, which silently stops the reading early and drops that record. Use the AsSourceBlockAsync overloads for a bounded block, or when the caller should not be blocked.
Mapping is done by an internal pipeline, so the last records and the completion of the block can arrive shortly after this method returns.
Exceptions
- ArgumentNullException
commandis null.
AsSourceBlock(IExecuteReader, DataflowBlockOptions?)
Reads the results of an IExecuteReader to the end, posting each record as an array of values to a new BufferBlock<T>, and returns the block.
public static IReceivableSourceBlock<object[]> AsSourceBlock(this IExecuteReader command, DataflowBlockOptions? options = null)
Parameters
commandIExecuteReaderThe expressive command to execute. The connection follows the command's ownership rules: it is opened only if needed and released when reading finishes. The command's own cancellation token applies.
optionsDataflowBlockOptionsOptions for the returned block, such as its bounded capacity, or null for the defaults.
Returns
- IReceivableSourceBlock<object[]>
The block that receives the records. It is completed after the last record has been delivered, or faulted with the exception that ended the reading.
Remarks
This method is synchronous: it returns only after the source has been read to the end (or the block declined a record), so the calling thread is blocked while the database responds. Exceptions from reading propagate to the caller.
Records are posted without waiting for room. With the default unbounded options every record is accepted, but if options sets a bounded capacity, a full block declines the next record, which silently stops the reading early and drops that record. Use the AsSourceBlockAsync overloads for a bounded block, or when the caller should not be blocked.
Exceptions
- ArgumentNullException
commandis null.
AsSourceBlock(IExecuteReader, ArrayPool<object>, DataflowBlockOptions?)
Reads the results of an IExecuteReader to the end, posting each record as an array of values rented from an array pool to a new BufferBlock<T>, and returns the block.
public static IReceivableSourceBlock<object[]> AsSourceBlock(this IExecuteReader command, ArrayPool<object> arrayPool, DataflowBlockOptions? options = null)
Parameters
commandIExecuteReaderThe expressive command to execute. The connection follows the command's ownership rules: it is opened only if needed and released when reading finishes. The command's own cancellation token applies.
arrayPoolArrayPool<object>The array pool to rent each record's array from. The consumer of the records is responsible for returning each array to the pool.
optionsDataflowBlockOptionsOptions for the returned block, such as its bounded capacity, or null for the defaults.
Returns
- IReceivableSourceBlock<object[]>
The block that receives the records. It is completed after the last record has been delivered, or faulted with the exception that ended the reading.
Remarks
This method is synchronous: it returns only after the source has been read to the end (or the block declined a record), so the calling thread is blocked while the database responds. Exceptions from reading propagate to the caller.
Records are posted without waiting for room. With the default unbounded options every record is accepted, but if options sets a bounded capacity, a full block declines the next record, which silently stops the reading early and drops that record. Use the AsSourceBlockAsync overloads for a bounded block, or when the caller should not be blocked.
Exceptions
- ArgumentNullException
commandis null.
AsSourceBlock<T>(IExecuteReader, Func<IDataRecord, T>, DataflowBlockOptions?)
Reads the results of an IExecuteReader to the end, posting each record after it has been transformed by transform to a new BufferBlock<T>, and returns the block.
public static IReceivableSourceBlock<T> AsSourceBlock<T>(this IExecuteReader command, Func<IDataRecord, T> transform, DataflowBlockOptions? options = null)
Parameters
commandIExecuteReaderThe expressive command to execute. The connection follows the command's ownership rules: it is opened only if needed and released when reading finishes. The command's own cancellation token applies.
transformFunc<IDataRecord, T>The function that transforms each IDataRecord into the item delivered to the block.
optionsDataflowBlockOptionsOptions for the returned block, such as its bounded capacity, or null for the defaults.
Returns
- IReceivableSourceBlock<T>
The block that receives the records. It is completed after the last record has been delivered, or faulted with the exception that ended the reading.
Type Parameters
TThe type of the items delivered to the block: the return type of the transform function.
Remarks
This method is synchronous: it returns only after the source has been read to the end (or the block declined a record), so the calling thread is blocked while the database responds. Exceptions from reading propagate to the caller.
Records are posted without waiting for room. With the default unbounded options every record is accepted, but if options sets a bounded capacity, a full block declines the next record, which silently stops the reading early and drops that record. Use the AsSourceBlockAsync overloads for a bounded block, or when the caller should not be blocked.
Exceptions
- ArgumentNullException
commandis null.
AsSourceBlock<T>(IExecuteReader, DataflowBlockOptions?)
Reads the results of an IExecuteReader to the end, posting each record mapped to a new instance of T to a new BufferBlock<T>, and returns the block.
public static IReceivableSourceBlock<T> AsSourceBlock<T>(this IExecuteReader command, DataflowBlockOptions? options = null) where T : new()
Parameters
commandIExecuteReaderThe expressive command to execute. The connection follows the command's ownership rules: it is opened only if needed and released when reading finishes. The command's own cancellation token applies.
optionsDataflowBlockOptionsOptions for the returned block, such as its bounded capacity, or null for the defaults.
Returns
- IReceivableSourceBlock<T>
The block that receives the records. It is completed after the last record has been delivered, or faulted with the exception that ended the reading.
Type Parameters
TThe type each record is mapped to.
Remarks
This method is synchronous: it returns only after the source has been read to the end (or the block declined a record), so the calling thread is blocked while the database responds. Exceptions from reading propagate to the caller.
Records are posted without waiting for room. With the default unbounded options every record is accepted, but if options sets a bounded capacity, a full block declines the next record, which silently stops the reading early and drops that record. Use the AsSourceBlockAsync overloads for a bounded block, or when the caller should not be blocked.
Mapping is done by an internal pipeline, so the last records and the completion of the block can arrive shortly after this method returns.
Exceptions
- ArgumentNullException
commandis null.
AsSourceBlock<T>(IExecuteReader, IEnumerable<(string Field, string? Column)>, DataflowBlockOptions?)
Reads the results of an IExecuteReader to the end, posting each record mapped to a new instance of T, using the field-to-column overrides to a new BufferBlock<T>, and returns the block.
public static IReceivableSourceBlock<T> AsSourceBlock<T>(this IExecuteReader command, IEnumerable<(string Field, string? Column)> fieldMappingOverrides, DataflowBlockOptions? options = null) where T : new()
Parameters
commandIExecuteReaderThe expressive command to execute. The connection follows the command's ownership rules: it is opened only if needed and released when reading finishes. The command's own cancellation token applies.
fieldMappingOverridesIEnumerable<(string Field, string Column)>An override map of field names to column names, applied on top of the default name-based mapping.
optionsDataflowBlockOptionsOptions for the returned block, such as its bounded capacity, or null for the defaults.
Returns
- IReceivableSourceBlock<T>
The block that receives the records. It is completed after the last record has been delivered, or faulted with the exception that ended the reading.
Type Parameters
TThe type each record is mapped to.
Remarks
This method is synchronous: it returns only after the source has been read to the end (or the block declined a record), so the calling thread is blocked while the database responds. Exceptions from reading propagate to the caller.
Records are posted without waiting for room. With the default unbounded options every record is accepted, but if options sets a bounded capacity, a full block declines the next record, which silently stops the reading early and drops that record. Use the AsSourceBlockAsync overloads for a bounded block, or when the caller should not be blocked.
Mapping is done by an internal pipeline, so the last records and the completion of the block can arrive shortly after this method returns.
Exceptions
- ArgumentNullException
commandis null.