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.

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 of the value returned by the action.

Remarks

The connection is not opened by this method. 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.

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

The connection is not opened by this method. 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<TConnection, T>(IDbConnectionFactory<TConnection>, Func<TConnection, T>)

Creates a connection from the factory, invokes the action, and then disposes the connection.

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

Parameters

connectionFactory IDbConnectionFactory<TConnection>

The connection factory to create the connection from.

action Func<TConnection, T>

The action to execute. It receives the connection.

Returns

T

The value returned by the action.

Type Parameters

TConnection

The type of the connection.

T

The type of the value returned by the action.

Remarks

The connection is not opened by this method. 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<TConnection>(IDbConnectionFactory<TConnection>, Action<TConnection>)

Creates a connection from the factory, invokes the action, and then disposes the connection.

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

Parameters

connectionFactory IDbConnectionFactory<TConnection>

The connection factory to create the connection from.

action Action<TConnection>

The action to execute. It receives the connection.

Type Parameters

TConnection

The type of the connection.

Remarks

The connection is not opened by this method. 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.

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 of the value returned by the action.

Remarks

The connection is not opened by this method. 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.

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

The connection is not opened by this method. 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<TConnection, T>(IDbConnectionPool<TConnection>, Func<TConnection, T>)

Takes a connection from the pool, invokes the action, and then gives the connection back to the pool.

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

Parameters

connectionPool IDbConnectionPool<TConnection>

The connection pool to take the connection from.

action Func<TConnection, T>

The action to execute. It receives the connection.

Returns

T

The value returned by the action.

Type Parameters

TConnection

The type of the connection.

T

The type of the value returned by the action.

Remarks

The connection is not opened by this method. 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<TConnection>(IDbConnectionPool<TConnection>, Action<TConnection>)

Takes a connection from the pool, invokes the action, and then gives the connection back to the pool.

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

Parameters

connectionPool IDbConnectionPool<TConnection>

The connection pool to take the connection from.

action Action<TConnection>

The action to execute. It receives the connection.

Type Parameters

TConnection

The type of the connection.

Remarks

The connection is not opened by this method. 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<TConnection, T>(Func<TConnection>, Func<TConnection, T>)

Invokes the function to create a connection, invokes the action, and then disposes the connection.

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

Parameters

connectionFactory Func<TConnection>

The function that creates the connection.

action Func<TConnection, T>

The action to execute. It receives the connection.

Returns

T

The value returned by the action.

Type Parameters

TConnection

The type of the connection.

T

The type of the value returned by the action.

Remarks

The connection is not opened by this method. 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<TConnection>(Func<TConnection>, Action<TConnection>)

Invokes the function to create a connection, invokes the action, and then disposes the connection.

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

Parameters

connectionFactory Func<TConnection>

The function that creates the connection.

action Action<TConnection>

The action to execute. It receives the connection.

Type Parameters

TConnection

The type of the connection.

Remarks

The connection is not opened by this method. Useful for single-line operations. Exceptions thrown by the action propagate after the connection has been disposed.

Exceptions

ArgumentNullException

connectionFactory or action is null.