Table of Contents

Method Open

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

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

Creates a connection from the factory, opens it if needed, invokes the action, and then disposes the connection.

public static T Open<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.

See Also

Open(IDbConnectionFactory, Action<IDbConnection>)

Creates a connection from the factory, opens it if needed, invokes the action, and then disposes the connection.

public static void Open(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.

Open<TConnection, T>(IDbConnectionFactory<TConnection>, Func<TConnection, T>)

Creates a connection from the factory, opens it if needed, invokes the action, and then disposes the connection.

public static T Open<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 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.

Open<TConnection>(IDbConnectionFactory<TConnection>, Action<TConnection>)

Creates a connection from the factory, opens it if needed, invokes the action, and then disposes the connection.

public static void Open<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 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.

Open<T>(IDbConnectionPool, Func<IDbConnection, ConnectionState, T>)

Takes a connection from the pool, opens it if needed, invokes the action with the connection and the state it was in before being opened, and then gives the connection back to the pool.

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

Parameters

connectionPool IDbConnectionPool

The connection pool to take the connection from.

action Func<IDbConnection, ConnectionState, T>

The action to execute. It receives the connection and the ConnectionState the connection was in before it was opened.

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.

Open(IDbConnectionPool, Action<IDbConnection, ConnectionState>)

Takes a connection from the pool, opens it if needed, invokes the action with the connection and the state it was in before being opened, and then gives the connection back to the pool.

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

Parameters

connectionPool IDbConnectionPool

The connection pool to take the connection from.

action Action<IDbConnection, ConnectionState>

The action to execute. It receives the connection and the ConnectionState the connection was in before it was opened.

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.

Open<TConnection, T>(IDbConnectionPool<TConnection>, Func<TConnection, ConnectionState, T>)

Takes a connection from the pool, opens it if needed, invokes the action with the connection and the state it was in before being opened, and then gives the connection back to the pool.

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

Parameters

connectionPool IDbConnectionPool<TConnection>

The connection pool to take the connection from.

action Func<TConnection, ConnectionState, T>

The action to execute. It receives the connection and the ConnectionState the connection was in before it was opened.

Returns

T

The value returned by the action.

Type Parameters

TConnection

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.

Open<TConnection>(IDbConnectionPool<TConnection>, Action<TConnection, ConnectionState>)

Takes a connection from the pool, opens it if needed, invokes the action with the connection and the state it was in before being opened, and then gives the connection back to the pool.

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

Parameters

connectionPool IDbConnectionPool<TConnection>

The connection pool to take the connection from.

action Action<TConnection, ConnectionState>

The action to execute. It receives the connection and the ConnectionState the connection was in before it was opened.

Type Parameters

TConnection

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.

Open<TConnection, T>(Func<TConnection>, Func<TConnection, T>)

Invokes the function to create a connection, opens it if needed, invokes the action, and then disposes the connection.

public static T Open<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 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.

Open<TConnection>(Func<TConnection>, Action<TConnection>)

Invokes the function to create a connection, opens it if needed, invokes the action, and then disposes the connection.

public static void Open<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 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.