Method UsingAsync
- Namespace
- Open.Database.Extensions
- Assembly
- Open.Database.Extensions.Core.dll
UsingAsync<T>(IDbConnectionFactory, Func<IDbConnection, ValueTask<T>>)
Creates a connection from the factory, invokes the asynchronous action, and then disposes the connection. The connection is not opened by this method.
public static ValueTask<T> UsingAsync<T>(this IDbConnectionFactory connectionFactory, Func<IDbConnection, ValueTask<T>> action)
Parameters
connectionFactoryIDbConnectionFactoryThe connection factory to create the connection from.
actionFunc<IDbConnection, ValueTask<T>>The asynchronous action to execute. It receives the connection.
Returns
- ValueTask<T>
A task that produces the value returned by the action after the connection has been released.
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. The exception is reported through the returned task.
UsingAsync(IDbConnectionFactory, Func<IDbConnection, ValueTask>)
Creates a connection from the factory, invokes the asynchronous action, and then disposes the connection. The connection is not opened by this method.
public static ValueTask UsingAsync(this IDbConnectionFactory connectionFactory, Func<IDbConnection, ValueTask> action)
Parameters
connectionFactoryIDbConnectionFactoryThe connection factory to create the connection from.
actionFunc<IDbConnection, ValueTask>The asynchronous action to execute. It receives the connection.
Returns
- ValueTask
A task that completes after the action has completed and the connection has been released.
Remarks
Useful for single-line operations. Exceptions thrown by the action propagate after the connection has been disposed.
Exceptions
- ArgumentNullException
connectionFactoryoractionis null. The exception is reported through the returned task.
UsingAsync<TConn, T>(IDbConnectionFactory<TConn>, Func<TConn, ValueTask<T>>)
Creates a connection from the factory, invokes the asynchronous action, and then disposes the connection. The connection is not opened by this method.
public static ValueTask<T> UsingAsync<TConn, T>(this IDbConnectionFactory<TConn> connectionFactory, Func<TConn, ValueTask<T>> action) where TConn : IDbConnection
Parameters
connectionFactoryIDbConnectionFactory<TConn>The connection factory to create the connection from.
actionFunc<TConn, ValueTask<T>>The asynchronous action to execute. It receives the connection.
Returns
- ValueTask<T>
A task that produces the value returned by the action after the connection has been released.
Type Parameters
TConnThe 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. The exception is reported through the returned task.
UsingAsync<TConn>(IDbConnectionFactory<TConn>, Func<TConn, ValueTask>)
Creates a connection from the factory, invokes the asynchronous action, and then disposes the connection. The connection is not opened by this method.
public static ValueTask UsingAsync<TConn>(this IDbConnectionFactory<TConn> connectionFactory, Func<TConn, ValueTask> action) where TConn : IDbConnection
Parameters
connectionFactoryIDbConnectionFactory<TConn>The connection factory to create the connection from.
actionFunc<TConn, ValueTask>The asynchronous action to execute. It receives the connection.
Returns
- ValueTask
A task that completes after the action has completed and the connection has been released.
Type Parameters
TConnThe connection type.
Remarks
Useful for single-line operations. Exceptions thrown by the action propagate after the connection has been disposed.
Exceptions
- ArgumentNullException
connectionFactoryoractionis null. The exception is reported through the returned task.
UsingAsync<T>(IDbConnectionPool, Func<IDbConnection, ValueTask<T>>)
Asynchronously 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 ValueTask<T> UsingAsync<T>(this IDbConnectionPool connectionPool, Func<IDbConnection, ValueTask<T>> action)
Parameters
connectionPoolIDbConnectionPoolThe connection pool to take the connection from.
actionFunc<IDbConnection, ValueTask<T>>The asynchronous action to execute. It receives the connection.
Returns
- ValueTask<T>
A task that produces the value returned by the action after the connection has been released.
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. The exception is reported through the returned task.
UsingAsync(IDbConnectionPool, Func<IDbConnection, ValueTask>)
Asynchronously 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 ValueTask UsingAsync(this IDbConnectionPool connectionPool, Func<IDbConnection, ValueTask> action)
Parameters
connectionPoolIDbConnectionPoolThe connection pool to take the connection from.
actionFunc<IDbConnection, ValueTask>The asynchronous action to execute. It receives the connection.
Returns
- ValueTask
A task that completes after the action has completed and the connection has been released.
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. The exception is reported through the returned task.
UsingAsync<TConn, T>(IDbConnectionPool<TConn>, Func<TConn, ValueTask<T>>)
Asynchronously 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 ValueTask<T> UsingAsync<TConn, T>(this IDbConnectionPool<TConn> connectionPool, Func<TConn, ValueTask<T>> action) where TConn : IDbConnection
Parameters
connectionPoolIDbConnectionPool<TConn>The connection pool to take the connection from.
actionFunc<TConn, ValueTask<T>>The asynchronous action to execute. It receives the connection.
Returns
- ValueTask<T>
A task that produces the value returned by the action after the connection has been released.
Type Parameters
TConnThe 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. The exception is reported through the returned task.
UsingAsync<TConn>(IDbConnectionPool<TConn>, Func<TConn, ValueTask>)
Asynchronously 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 ValueTask UsingAsync<TConn>(this IDbConnectionPool<TConn> connectionPool, Func<TConn, ValueTask> action) where TConn : IDbConnection
Parameters
connectionPoolIDbConnectionPool<TConn>The connection pool to take the connection from.
actionFunc<TConn, ValueTask>The asynchronous action to execute. It receives the connection.
Returns
- ValueTask
A task that completes after the action has completed and the connection has been released.
Type Parameters
TConnThe 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. The exception is reported through the returned task.
UsingAsync<TConn, T>(Func<TConn>, Func<TConn, ValueTask<T>>)
Invokes the function to create a connection, invokes the asynchronous action, and then disposes the connection. The connection is not opened by this method.
public static ValueTask<T> UsingAsync<TConn, T>(this Func<TConn> connectionFactory, Func<TConn, ValueTask<T>> action) where TConn : IDbConnection
Parameters
connectionFactoryFunc<TConn>The function that creates the connection.
actionFunc<TConn, ValueTask<T>>The asynchronous action to execute. It receives the connection.
Returns
- ValueTask<T>
A task that produces the value returned by the action after the connection has been released.
Type Parameters
TConnThe 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. The exception is reported through the returned task.
UsingAsync<TConn>(Func<TConn>, Func<TConn, ValueTask>)
Invokes the function to create a connection, invokes the asynchronous action, and then disposes the connection. The connection is not opened by this method.
public static ValueTask UsingAsync<TConn>(this Func<TConn> connectionFactory, Func<TConn, ValueTask> action) where TConn : IDbConnection
Parameters
connectionFactoryFunc<TConn>The function that creates the connection.
actionFunc<TConn, ValueTask>The asynchronous action to execute. It receives the connection.
Returns
- ValueTask
A task that completes after the action has completed and the connection has been released.
Type Parameters
TConnThe connection type.
Remarks
Useful for single-line operations. Exceptions thrown by the action propagate after the connection has been disposed.
Exceptions
- ArgumentNullException
connectionFactoryoractionis null. The exception is reported through the returned task.