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
connectionFactoryIDbConnectionFactoryThe connection factory to create the connection from.
actionFunc<IDbConnection, T>The action to execute. It receives the connection.
Returns
- T
The value returned by the action.
Type Parameters
TThe 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
connectionFactoryoractionis 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
connectionFactoryIDbConnectionFactoryThe connection factory to create the connection from.
actionAction<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
connectionFactoryoractionis 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
connectionFactoryIDbConnectionFactory<TConnection>The connection factory to create the connection from.
actionFunc<TConnection, T>The action to execute. It receives the connection.
Returns
- T
The value returned by the action.
Type Parameters
TConnectionThe connection type.
TThe 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
connectionFactoryoractionis 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
connectionFactoryIDbConnectionFactory<TConnection>The connection factory to create the connection from.
actionAction<TConnection>The action to execute. It receives the connection.
Type Parameters
TConnectionThe connection type.
Remarks
Useful for single-line operations. Exceptions thrown by the action propagate after the connection has been disposed.
Exceptions
- ArgumentNullException
connectionFactoryoractionis 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
connectionPoolIDbConnectionPoolThe connection pool to take the connection from.
actionFunc<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
TThe 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
connectionPooloractionis 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
connectionPoolIDbConnectionPoolThe connection pool to take the connection from.
actionAction<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
connectionPooloractionis 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
connectionPoolIDbConnectionPool<TConnection>The connection pool to take the connection from.
actionFunc<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
TConnectionThe connection type.
TThe 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
connectionPooloractionis 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
connectionPoolIDbConnectionPool<TConnection>The connection pool to take the connection from.
actionAction<TConnection, ConnectionState>The action to execute. It receives the connection and the ConnectionState the connection was in before it was opened.
Type Parameters
TConnectionThe 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
connectionPooloractionis 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
connectionFactoryFunc<TConnection>The function that creates the connection.
actionFunc<TConnection, T>The action to execute. It receives the connection.
Returns
- T
The value returned by the action.
Type Parameters
TConnectionThe connection type.
TThe 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
connectionFactoryoractionis 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
connectionFactoryFunc<TConnection>The function that creates the connection.
actionAction<TConnection>The action to execute. It receives the connection.
Type Parameters
TConnectionThe connection type.
Remarks
Useful for single-line operations. Exceptions thrown by the action propagate after the connection has been disposed.
Exceptions
- ArgumentNullException
connectionFactoryoractionis null.