Table of Contents

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

command IDbCommand

The IDbCommand to generate a reader from.

handler Action<IDataReader>

The function that receives the reader.

behavior CommandBehavior

The 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

command or handler is 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

command IDbCommand

The IDbCommand to generate a reader from.

transform Func<IDataReader, T>

The function that receives the reader and returns the result.

behavior CommandBehavior

The behavior to use with the data reader. The default is Default.

Returns

T

The result of the transform.

Type Parameters

T

The 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

command or transform is null.