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.
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 represents the asynchronous operation; its result is the value returned by the action, produced after the connection has been released.
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. 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.
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 represents the asynchronous operation. It completes after the action has completed and the connection has been released.
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. The exception is reported through the returned task.
UsingAsync<TConnection, T>(IDbConnectionFactory<TConnection>, Func<TConnection, ValueTask<T>>)
Creates a connection from the factory, invokes the asynchronous action, and then disposes the connection.
public static ValueTask<T> UsingAsync<TConnection, T>(this IDbConnectionFactory<TConnection> connectionFactory, Func<TConnection, ValueTask<T>> action) where TConnection : IDbConnection
Parameters
connectionFactoryIDbConnectionFactory<TConnection>The connection factory to create the connection from.
actionFunc<TConnection, ValueTask<T>>The asynchronous action to execute. It receives the connection.
Returns
- ValueTask<T>
A task that represents the asynchronous operation; its result is the value returned by the action, produced after the connection has been released.
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. The exception is reported through the returned task.
UsingAsync<TConnection>(IDbConnectionFactory<TConnection>, Func<TConnection, ValueTask>)
Creates a connection from the factory, invokes the asynchronous action, and then disposes the connection.
public static ValueTask UsingAsync<TConnection>(this IDbConnectionFactory<TConnection> connectionFactory, Func<TConnection, ValueTask> action) where TConnection : IDbConnection
Parameters
connectionFactoryIDbConnectionFactory<TConnection>The connection factory to create the connection from.
actionFunc<TConnection, ValueTask>The asynchronous action to execute. It receives the connection.
Returns
- ValueTask
A task that represents the asynchronous operation. It completes after the action has completed and the connection has been released.
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. 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.
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 represents the asynchronous operation; its result is the value returned by the action, produced after the connection has been released.
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. 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.
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 represents the asynchronous operation. It completes after the action has completed and the connection has been released.
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. The exception is reported through the returned task.
UsingAsync<TConnection, T>(IDbConnectionPool<TConnection>, Func<TConnection, ValueTask<T>>)
Asynchronously takes a connection from the pool, invokes the action, and then gives the connection back to the pool.
public static ValueTask<T> UsingAsync<TConnection, T>(this IDbConnectionPool<TConnection> connectionPool, Func<TConnection, ValueTask<T>> action) where TConnection : IDbConnection
Parameters
connectionPoolIDbConnectionPool<TConnection>The connection pool to take the connection from.
actionFunc<TConnection, ValueTask<T>>The asynchronous action to execute. It receives the connection.
Returns
- ValueTask<T>
A task that represents the asynchronous operation; its result is the value returned by the action, produced after the connection has been released.
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. The exception is reported through the returned task.
UsingAsync<TConnection>(IDbConnectionPool<TConnection>, Func<TConnection, ValueTask>)
Asynchronously takes a connection from the pool, invokes the action, and then gives the connection back to the pool.
public static ValueTask UsingAsync<TConnection>(this IDbConnectionPool<TConnection> connectionPool, Func<TConnection, ValueTask> action) where TConnection : IDbConnection
Parameters
connectionPoolIDbConnectionPool<TConnection>The connection pool to take the connection from.
actionFunc<TConnection, ValueTask>The asynchronous action to execute. It receives the connection.
Returns
- ValueTask
A task that represents the asynchronous operation. It completes after the action has completed and the connection has been released.
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. The exception is reported through the returned task.
UsingAsync<TConnection, T>(Func<TConnection>, Func<TConnection, ValueTask<T>>)
Invokes the function to create a connection, invokes the asynchronous action, and then disposes the connection.
public static ValueTask<T> UsingAsync<TConnection, T>(this Func<TConnection> connectionFactory, Func<TConnection, ValueTask<T>> action) where TConnection : IDbConnection
Parameters
connectionFactoryFunc<TConnection>The function that creates the connection.
actionFunc<TConnection, ValueTask<T>>The asynchronous action to execute. It receives the connection.
Returns
- ValueTask<T>
A task that represents the asynchronous operation; its result is the value returned by the action, produced after the connection has been released.
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. The exception is reported through the returned task.
UsingAsync<TConnection>(Func<TConnection>, Func<TConnection, ValueTask>)
Invokes the function to create a connection, invokes the asynchronous action, and then disposes the connection.
public static ValueTask UsingAsync<TConnection>(this Func<TConnection> connectionFactory, Func<TConnection, ValueTask> action) where TConnection : IDbConnection
Parameters
connectionFactoryFunc<TConnection>The function that creates the connection.
actionFunc<TConnection, ValueTask>The asynchronous action to execute. It receives the connection.
Returns
- ValueTask
A task that represents the asynchronous operation. It completes after the action has completed and the connection has been released.
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. The exception is reported through the returned task.