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
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 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
connectionFactoryoractionis 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
connectionFactoryIDbConnectionFactoryThe connection factory to create the connection from.
actionAction<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
connectionFactoryoractionis 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
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 type of the connection.
TThe 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
connectionFactoryoractionis 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
connectionFactoryIDbConnectionFactory<TConnection>The connection factory to create the connection from.
actionAction<TConnection>The action to execute. It receives the connection.
Type Parameters
TConnectionThe 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
connectionFactoryoractionis 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
connectionPoolIDbConnectionPoolThe connection pool to take 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 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
connectionPooloractionis 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
connectionPoolIDbConnectionPoolThe connection pool to take the connection from.
actionAction<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
connectionPooloractionis 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
connectionPoolIDbConnectionPool<TConnection>The connection pool to take 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 type of the connection.
TThe 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
connectionPooloractionis 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
connectionPoolIDbConnectionPool<TConnection>The connection pool to take the connection from.
actionAction<TConnection>The action to execute. It receives the connection.
Type Parameters
TConnectionThe 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
connectionPooloractionis 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
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 type of the connection.
TThe 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
connectionFactoryoractionis 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
connectionFactoryFunc<TConnection>The function that creates the connection.
actionAction<TConnection>The action to execute. It receives the connection.
Type Parameters
TConnectionThe 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
connectionFactoryoractionis null.