Table of Contents

Method OpenAsync

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

OpenAsync(IDbConnection, CancellationToken)

Opens the connection by calling OpenAsync(CancellationToken) if it is a DbConnection, and Open() otherwise.

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

Parameters

connection IDbConnection

The connection to open.

cancellationToken CancellationToken

A token that cancels opening a DbConnection. It is ignored for any other connection.

Returns

ValueTask

A task that represents the asynchronous operation.

Remarks

Unlike EnsureOpenAsync(IDbConnection, CancellationToken), this method does not check the state of the connection first, and does not return it.

Exceptions

ArgumentNullException

connection is null. It is thrown by the call, not through the returned task.

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

Useful for single-line operations. Exceptions thrown by the action propagate after the connection has been disposed. If opening the connection throws, it is disposed before the exception propagates.

Exceptions

ArgumentNullException

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

OperationCanceledException

cancellationToken was canceled before or 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 represents the asynchronous operation. It 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. If opening the connection throws, it is disposed before the exception propagates.

Exceptions

ArgumentNullException

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

OperationCanceledException

cancellationToken was canceled before or 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 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

Useful for single-line operations. Exceptions thrown by the action propagate after the connection has been disposed. If opening the connection throws, it is disposed before the exception propagates.

Exceptions

ArgumentNullException

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

OperationCanceledException

cancellationToken was canceled before or 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 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

Useful for single-line operations. Exceptions thrown by the action propagate after the connection has been disposed. If opening the connection throws, it is disposed before the exception propagates.

Exceptions

ArgumentNullException

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

OperationCanceledException

cancellationToken was canceled before or 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 asynchronous 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 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

Useful for single-line operations. Exceptions thrown by the action propagate after the connection has been given back to the pool. If opening the connection throws, it is given back before the exception propagates.

Exceptions

ArgumentNullException

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

OperationCanceledException

cancellationToken was canceled before or 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 asynchronous 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 represents the asynchronous operation. It 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. If opening the connection throws, it is given back before the exception propagates.

Exceptions

ArgumentNullException

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

OperationCanceledException

cancellationToken was canceled before or 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 asynchronous 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 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

Useful for single-line operations. Exceptions thrown by the action propagate after the connection has been given back to the pool. If opening the connection throws, it is given back before the exception propagates.

Exceptions

ArgumentNullException

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

OperationCanceledException

cancellationToken was canceled before or 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 asynchronous 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 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

Useful for single-line operations. Exceptions thrown by the action propagate after the connection has been given back to the pool. If opening the connection throws, it is given back before the exception propagates.

Exceptions

ArgumentNullException

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

OperationCanceledException

cancellationToken was canceled before or 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 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

Useful for single-line operations. Exceptions thrown by the action propagate after the connection has been disposed. If opening the connection throws, it is disposed before the exception propagates.

Exceptions

ArgumentNullException

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

OperationCanceledException

cancellationToken was canceled before or 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 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

Useful for single-line operations. Exceptions thrown by the action propagate after the connection has been disposed. If opening the connection throws, it is disposed before the exception propagates.

Exceptions

ArgumentNullException

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

OperationCanceledException

cancellationToken was canceled before or while the connection was being opened.