Method ExecuteReader
- Namespace
- Open.Database.Extensions.Synchronous
- Assembly
- Open.Database.Extensions.Core.dll
ExecuteReader(IDbCommand, Action<IDataReader>, CommandBehavior)
Executes a reader and passes it to a handler.
public static void ExecuteReader(this IDbCommand command, Action<IDataReader> handler, CommandBehavior behavior = CommandBehavior.Default)
Parameters
commandIDbCommandThe IDbCommand to generate a reader from.
handlerAction<IDataReader>The function that receives the reader.
behaviorCommandBehaviorThe behavior to use with the data reader. The default is Default.
Remarks
The connection is opened if it is closed, and closed again when the call finishes; a connection that was already open is left as it was. A connection this call opened is also closed, never disposed, when the reader cannot be created.
Exceptions
- ArgumentNullException
commandorhandleris null.
ExecuteReader<T>(IDbCommand, Func<IDataReader, T>, CommandBehavior)
Executes a reader and returns the result of a transform function applied to it.
public static T ExecuteReader<T>(this IDbCommand command, Func<IDataReader, T> transform, CommandBehavior behavior = CommandBehavior.Default)
Parameters
commandIDbCommandThe IDbCommand to generate a reader from.
transformFunc<IDataReader, T>The function that receives the reader and returns the result.
behaviorCommandBehaviorThe behavior to use with the data reader. The default is Default.
Returns
- T
The result of the transform.
Type Parameters
TThe return type of the transform function.
Remarks
The connection is opened if it is closed, and closed again when the call finishes; a connection that was already open is left as it was. A connection this call opened is also closed, never disposed, when the reader cannot be created.
Exceptions
- ArgumentNullException
commandortransformis null.