Table of Contents

Method OpenAsync

Namespace
Open.Database.Extensions
Assembly
Open.Database.Extensions.Core.dll

OpenAsync(IDbConnection, bool, CancellationToken)

If the connection derives from DbConnection, this will call OpenAsync(CancellationToken); otherwise it will call Open().

public static ValueTask OpenAsync(this IDbConnection connection, bool configureAwait = true, CancellationToken cancellationToken = default)

Parameters

connection IDbConnection

The connection to transact with.

configureAwait bool

If true (default) will retain the context after opening.

cancellationToken CancellationToken

An cancellation token to cancel opening.

Returns

ValueTask

A task containing the prior connection state.

OpenAsync<T>(IDbConnectionFactory, Func<IDbConnection, ValueTask<T>>, CancellationToken)

Creates a connection from the factory, asynchronously opens it if needed, invokes the action, and then disposes the connection.

public static ValueTask<T> OpenAsync<T>(this IDbConnectionFactory connectionFactory, Func<IDbConnection, ValueTask<T>> action, CancellationToken cancellationToken = default)

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.

cancellationToken CancellationToken

A token that cancels opening 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.

OperationCanceledException

cancellationToken was canceled while the connection was being opened.

OpenAsync(IDbConnectionFactory, Func<IDbConnection, ValueTask>, CancellationToken)

Creates a connection from the factory, asynchronously opens it if needed, invokes the action, and then disposes the connection.

public static ValueTask OpenAsync(this IDbConnectionFactory connectionFactory, Func<IDbConnection, ValueTask> action, CancellationToken cancellationToken = default)

Parameters

connectionFactory IDbConnectionFactory

The connection factory to create the connection from.

action Func<IDbConnection, ValueTask>

The asynchronous action to execute. It receives the connection.

cancellationToken CancellationToken

A token that cancels opening 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.

OperationCanceledException

cancellationToken was canceled while the connection was being opened.

OpenAsync<TConnection, T>(IDbConnectionFactory<TConnection>, Func<TConnection, ValueTask<T>>, CancellationToken)

Creates a connection from the factory, asynchronously opens it if needed, invokes the action, and then disposes the connection.

public static ValueTask<T> OpenAsync<TConnection, T>(this IDbConnectionFactory<TConnection> connectionFactory, Func<TConnection, ValueTask<T>> action, CancellationToken cancellationToken = default) 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.

cancellationToken CancellationToken

A token that cancels opening the connection.

Returns

ValueTask<T>

A task that produces the value returned by the action after the connection has been released.

Type Parameters

TConnection

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.

OperationCanceledException

cancellationToken was canceled while the connection was being opened.

OpenAsync<TConnection>(IDbConnectionFactory<TConnection>, Func<TConnection, ValueTask>, CancellationToken)

Creates a connection from the factory, asynchronously opens it if needed, invokes the action, and then disposes the connection.

public static ValueTask OpenAsync<TConnection>(this IDbConnectionFactory<TConnection> connectionFactory, Func<TConnection, ValueTask> action, CancellationToken cancellationToken = default) 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.

cancellationToken CancellationToken

A token that cancels opening the connection.

Returns

ValueTask

A task that completes after the action has completed and the connection has been released.

Type Parameters

TConnection

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.

OperationCanceledException

cancellationToken was canceled while the connection was being opened.

OpenAsync<T>(IDbConnectionPool, Func<IDbConnection, ConnectionState, ValueTask<T>>, CancellationToken)

Asynchronously takes a connection from the pool, opens it if needed, invokes the action with the connection and the state it was in before being opened, and then gives the connection back to the pool.

public static ValueTask<T> OpenAsync<T>(this IDbConnectionPool connectionPool, Func<IDbConnection, ConnectionState, ValueTask<T>> action, CancellationToken cancellationToken = default)

Parameters

connectionPool IDbConnectionPool

The connection pool to take the connection from.

action Func<IDbConnection, ConnectionState, ValueTask<T>>

The action to execute. It receives the connection and the ConnectionState the connection was in before it was opened.

cancellationToken CancellationToken

A token that cancels opening 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.

OperationCanceledException

cancellationToken was canceled while the connection was being opened.

OpenAsync(IDbConnectionPool, Func<IDbConnection, ConnectionState, ValueTask>, CancellationToken)

Asynchronously takes a connection from the pool, opens it if needed, invokes the action with the connection and the state it was in before being opened, and then gives the connection back to the pool.

public static ValueTask OpenAsync(this IDbConnectionPool connectionPool, Func<IDbConnection, ConnectionState, ValueTask> action, CancellationToken cancellationToken = default)

Parameters

connectionPool IDbConnectionPool

The connection pool to take the connection from.

action Func<IDbConnection, ConnectionState, ValueTask>

The action to execute. It receives the connection and the ConnectionState the connection was in before it was opened.

cancellationToken CancellationToken

A token that cancels opening 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.

OperationCanceledException

cancellationToken was canceled while the connection was being opened.

OpenAsync<TConnection, T>(IDbConnectionPool<TConnection>, Func<TConnection, ConnectionState, ValueTask<T>>, CancellationToken)

Asynchronously takes a connection from the pool, opens it if needed, invokes the action with the connection and the state it was in before being opened, and then gives the connection back to the pool.

public static ValueTask<T> OpenAsync<TConnection, T>(this IDbConnectionPool<TConnection> connectionPool, Func<TConnection, ConnectionState, ValueTask<T>> action, CancellationToken cancellationToken = default) where TConnection : IDbConnection

Parameters

connectionPool IDbConnectionPool<TConnection>

The connection pool to take the connection from.

action Func<TConnection, ConnectionState, ValueTask<T>>

The action to execute. It receives the connection and the ConnectionState the connection was in before it was opened.

cancellationToken CancellationToken

A token that cancels opening the connection.

Returns

ValueTask<T>

A task that produces the value returned by the action after the connection has been released.

Type Parameters

TConnection

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.

OperationCanceledException

cancellationToken was canceled while the connection was being opened.

OpenAsync<TConnection>(IDbConnectionPool<TConnection>, Func<TConnection, ConnectionState, ValueTask>, CancellationToken)

Asynchronously takes a connection from the pool, opens it if needed, invokes the action with the connection and the state it was in before being opened, and then gives the connection back to the pool.

public static ValueTask OpenAsync<TConnection>(this IDbConnectionPool<TConnection> connectionPool, Func<TConnection, ConnectionState, ValueTask> action, CancellationToken cancellationToken = default) where TConnection : IDbConnection

Parameters

connectionPool IDbConnectionPool<TConnection>

The connection pool to take the connection from.

action Func<TConnection, ConnectionState, ValueTask>

The action to execute. It receives the connection and the ConnectionState the connection was in before it was opened.

cancellationToken CancellationToken

A token that cancels opening the connection.

Returns

ValueTask

A task that completes after the action has completed and the connection has been released.

Type Parameters

TConnection

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.

OperationCanceledException

cancellationToken was canceled while the connection was being opened.

OpenAsync<TConnection, T>(Func<TConnection>, Func<TConnection, ValueTask<T>>, CancellationToken)

Invokes the function to create a connection, asynchronously opens it if needed, invokes the action, and then disposes the connection.

public static ValueTask<T> OpenAsync<TConnection, T>(this Func<TConnection> connectionFactory, Func<TConnection, ValueTask<T>> action, CancellationToken cancellationToken = default) 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.

cancellationToken CancellationToken

A token that cancels opening the connection.

Returns

ValueTask<T>

A task that produces the value returned by the action after the connection has been released.

Type Parameters

TConnection

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.

OperationCanceledException

cancellationToken was canceled while the connection was being opened.

OpenAsync<TConnection>(Func<TConnection>, Func<TConnection, ValueTask>, CancellationToken)

Invokes the function to create a connection, asynchronously opens it if needed, invokes the action, and then disposes the connection.

public static ValueTask OpenAsync<TConnection>(this Func<TConnection> connectionFactory, Func<TConnection, ValueTask> action, CancellationToken cancellationToken = default) 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.

cancellationToken CancellationToken

A token that cancels opening the connection.

Returns

ValueTask

A task that completes after the action has completed and the connection has been released.

Type Parameters

TConnection

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.

OperationCanceledException

cancellationToken was canceled while the connection was being opened.