Table of Contents

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

connectionFactory IDbConnectionFactory

The connection factory to create the connection from.

action Func<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

T

The 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

connectionFactory or action is 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

connectionFactory IDbConnectionFactory

The connection factory to create the connection from.

action Func<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

connectionFactory or action is 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

connectionFactory IDbConnectionFactory<TConnection>

The connection factory to create the connection from.

action Func<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

TConnection

The type of the connection.

T

The 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

connectionFactory or action is 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

connectionFactory IDbConnectionFactory<TConnection>

The connection factory to create the connection from.

action Func<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

TConnection

The 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

connectionFactory or action is 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

connectionPool IDbConnectionPool

The connection pool to take the connection from.

action Func<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

T

The 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

connectionPool or action is 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

connectionPool IDbConnectionPool

The connection pool to take the connection from.

action Func<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

connectionPool or action is 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

connectionPool IDbConnectionPool<TConnection>

The connection pool to take the connection from.

action Func<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

TConnection

The type of the connection.

T

The 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

connectionPool or action is 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

connectionPool IDbConnectionPool<TConnection>

The connection pool to take the connection from.

action Func<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

TConnection

The 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

connectionPool or action is 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

connectionFactory Func<TConnection>

The function that creates the connection.

action Func<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

TConnection

The type of the connection.

T

The 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

connectionFactory or action is 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

connectionFactory Func<TConnection>

The function that creates the connection.

action Func<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

TConnection

The 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

connectionFactory or action is null. The exception is reported through the returned task.