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. The connection is not opened by this method.

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 produces the value returned by the action after the connection has been released.

Type Parameters

T

The 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

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. The connection is not opened by this method.

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

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

connectionFactory IDbConnectionFactory<TConn>

The connection factory to create the connection from.

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

TConn

The connection type.

T

The 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

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

connectionFactory IDbConnectionFactory<TConn>

The connection factory to create the connection from.

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

TConn

The connection type.

Remarks

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. The connection is not opened by this method.

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 produces the value returned by the action after the connection has been released.

Type Parameters

T

The 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

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. The connection is not opened by this method.

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

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

connectionPool IDbConnectionPool<TConn>

The connection pool to take the connection from.

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

TConn

The connection type.

T

The 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

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

connectionPool IDbConnectionPool<TConn>

The connection pool to take the connection from.

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

TConn

The 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

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

connectionFactory Func<TConn>

The function that creates the connection.

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

TConn

The connection type.

T

The 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

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

connectionFactory Func<TConn>

The function that creates the connection.

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

TConn

The connection type.

Remarks

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.