Table of Contents

Method Using

Namespace
Open.Database.Extensions
Assembly
Open.Database.Extensions.Core.dll

Using<T>(IDbConnectionFactory, Func<IDbConnection, T>)

Creates a connection from the factory, invokes the action, and then disposes the connection. The connection is not opened by this method.

public static T Using<T>(this IDbConnectionFactory connectionFactory, Func<IDbConnection, T> action)

Parameters

connectionFactory IDbConnectionFactory

The connection factory to create the connection from.

action Func<IDbConnection, T>

The action to execute. It receives the connection.

Returns

T

The value returned by the action.

Type Parameters

T

The type returned from the action.

Remarks

Useful for single-line operations. Exceptions thrown by the action propagate after the connection has been disposed.

Exceptions

ArgumentNullException

connectionFactory or action is null.

Using(IDbConnectionFactory, Action<IDbConnection>)

Creates a connection from the factory, invokes the action, and then disposes the connection. The connection is not opened by this method.

public static void Using(this IDbConnectionFactory connectionFactory, Action<IDbConnection> action)

Parameters

connectionFactory IDbConnectionFactory

The connection factory to create the connection from.

action Action<IDbConnection>

The action to execute. It receives the connection.

Remarks

Useful for single-line operations. Exceptions thrown by the action propagate after the connection has been disposed.

Exceptions

ArgumentNullException

connectionFactory or action is null.

Using<TConn, T>(IDbConnectionFactory<TConn>, Func<TConn, T>)

Creates a connection from the factory, invokes the action, and then disposes the connection. The connection is not opened by this method.

public static T Using<TConn, T>(this IDbConnectionFactory<TConn> connectionFactory, Func<TConn, T> action) where TConn : IDbConnection

Parameters

connectionFactory IDbConnectionFactory<TConn>

The connection factory to create the connection from.

action Func<TConn, T>

The action to execute. It receives the connection.

Returns

T

The value returned by the action.

Type Parameters

TConn

The connection type.

T

The type returned from the action.

Remarks

Useful for single-line operations. Exceptions thrown by the action propagate after the connection has been disposed.

Exceptions

ArgumentNullException

connectionFactory or action is null.

Using<TConn>(IDbConnectionFactory<TConn>, Action<TConn>)

Creates a connection from the factory, invokes the action, and then disposes the connection. The connection is not opened by this method.

public static void Using<TConn>(this IDbConnectionFactory<TConn> connectionFactory, Action<TConn> action) where TConn : IDbConnection

Parameters

connectionFactory IDbConnectionFactory<TConn>

The connection factory to create the connection from.

action Action<TConn>

The action to execute. It receives the connection.

Type Parameters

TConn

The connection type.

Remarks

Useful for single-line operations. Exceptions thrown by the action propagate after the connection has been disposed.

Exceptions

ArgumentNullException

connectionFactory or action is null.

Using<T>(IDbConnectionPool, Func<IDbConnection, T>)

Takes a connection from the pool, invokes the action, and then gives the connection back to the pool. The connection is not opened by this method.

public static T Using<T>(this IDbConnectionPool connectionPool, Func<IDbConnection, T> action)

Parameters

connectionPool IDbConnectionPool

The connection pool to take the connection from.

action Func<IDbConnection, T>

The action to execute. It receives the connection.

Returns

T

The value returned by the action.

Type Parameters

T

The type returned from the action.

Remarks

Useful for single-line operations. Exceptions thrown by the action propagate after the connection has been given back to the pool.

Exceptions

ArgumentNullException

connectionPool or action is null.

Using(IDbConnectionPool, Action<IDbConnection>)

Takes a connection from the pool, invokes the action, and then gives the connection back to the pool. The connection is not opened by this method.

public static void Using(this IDbConnectionPool connectionPool, Action<IDbConnection> action)

Parameters

connectionPool IDbConnectionPool

The connection pool to take the connection from.

action Action<IDbConnection>

The action to execute. It receives the connection.

Remarks

Useful for single-line operations. Exceptions thrown by the action propagate after the connection has been given back to the pool.

Exceptions

ArgumentNullException

connectionPool or action is null.

Using<TConn, T>(IDbConnectionPool<TConn>, Func<TConn, T>)

Takes a connection from the pool, invokes the action, and then gives the connection back to the pool. The connection is not opened by this method.

public static T Using<TConn, T>(this IDbConnectionPool<TConn> connectionPool, Func<TConn, T> action) where TConn : IDbConnection

Parameters

connectionPool IDbConnectionPool<TConn>

The connection pool to take the connection from.

action Func<TConn, T>

The action to execute. It receives the connection.

Returns

T

The value returned by the action.

Type Parameters

TConn

The connection type.

T

The type returned from the action.

Remarks

Useful for single-line operations. Exceptions thrown by the action propagate after the connection has been given back to the pool.

Exceptions

ArgumentNullException

connectionPool or action is null.

Using<TConn>(IDbConnectionPool<TConn>, Action<TConn>)

Takes a connection from the pool, invokes the action, and then gives the connection back to the pool. The connection is not opened by this method.

public static void Using<TConn>(this IDbConnectionPool<TConn> connectionPool, Action<TConn> action) where TConn : IDbConnection

Parameters

connectionPool IDbConnectionPool<TConn>

The connection pool to take the connection from.

action Action<TConn>

The action to execute. It receives the connection.

Type Parameters

TConn

The connection type.

Remarks

Useful for single-line operations. Exceptions thrown by the action propagate after the connection has been given back to the pool.

Exceptions

ArgumentNullException

connectionPool or action is null.

Using<TConn, T>(Func<TConn>, Func<TConn, T>)

Invokes the function to create a connection, invokes the action, and then disposes the connection. The connection is not opened by this method.

public static T Using<TConn, T>(this Func<TConn> connectionFactory, Func<TConn, T> action) where TConn : IDbConnection

Parameters

connectionFactory Func<TConn>

The function that creates the connection.

action Func<TConn, T>

The action to execute. It receives the connection.

Returns

T

The value returned by the action.

Type Parameters

TConn

The connection type.

T

The type returned from the action.

Remarks

Useful for single-line operations. Exceptions thrown by the action propagate after the connection has been disposed.

Exceptions

ArgumentNullException

connectionFactory or action is null.

Using<TConn>(Func<TConn>, Action<TConn>)

Invokes the function to create a connection, invokes the action, and then disposes the connection. The connection is not opened by this method.

public static void Using<TConn>(this Func<TConn> connectionFactory, Action<TConn> action) where TConn : IDbConnection

Parameters

connectionFactory Func<TConn>

The function that creates the connection.

action Action<TConn>

The action to execute. It receives the connection.

Type Parameters

TConn

The connection type.

Remarks

Useful for single-line operations. Exceptions thrown by the action propagate after the connection has been disposed.

Exceptions

ArgumentNullException

connectionFactory or action is null.