Table of Contents

Class ConnectionExtensions

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

Core non-DB-specific extensions for database connections.

public static class ConnectionExtensions
Inheritance
ConnectionExtensions
Inherited Members

Remarks

The Command and StoredProcedure extension methods are the entry points to the expressive API. They create an ExpressiveCommand (or an ExpressiveDbCommand when the source is a DbConnection, a DbTransaction, or a typed factory or pool) from a connection, a transaction, a connection factory, a connection pool, or a factory function. Creating the command does no work; the database is first touched when an execute method is called on it.

The source decides who owns the connection:

  • A connection or transaction: the command runs on that connection. It is opened only if it is closed, closed again afterwards if the command opened it, and never disposed.
  • A connection factory or factory function: every execution creates a new connection, opens it if needed, and disposes it when finished.
  • A connection pool: every execution takes a connection from the pool, opens it if needed, and gives it back when finished.

Methods

Command(IDbConnectionFactory, string, CommandType)

Creates an ExpressiveCommand that creates a new connection from a connection factory for every execution.

Command(IDbConnectionPool, string, CommandType)

Creates an ExpressiveCommand that takes its connections from a connection pool.

Command(DbConnection, string, CommandType)

Creates an ExpressiveDbCommand that executes on the given connection.

Command(DbTransaction, string, CommandType)

Creates an ExpressiveDbCommand that executes within the given transaction.

Command(IDbConnection, string, CommandType)

Creates an ExpressiveCommand that executes on the given connection.

Command(IDbTransaction, string, CommandType)

Creates an ExpressiveCommand that executes within the given transaction.

Command(Func<IDbConnection>, string, CommandType)

Creates an ExpressiveCommand that invokes a function to create a new connection for every execution.

Command<TConnection>(IDbConnectionFactory<TConnection>, string, CommandType)

Creates an ExpressiveDbCommand that creates a new connection from a connection factory for every execution.

Command<TConnection>(IDbConnectionPool<TConnection>, string, CommandType)

Creates an ExpressiveDbCommand that takes its connections from a connection pool.

Command<TConnection>(Func<TConnection>, string, CommandType)

Creates an ExpressiveDbCommand that invokes a function to create a new connection for every execution.

CreateCommand(DbConnection, CommandType, string, int)

Creates a DbCommand from a DbConnection with the command type, text, and timeout already set.

CreateCommand(IDbConnection, CommandType, string, int)

Creates an IDbCommand from a connection with the command type, text, and timeout already set.

CreateStoredProcedureCommand(DbConnection, string, int)

Creates a stored procedure DbCommand from a DbConnection.

CreateStoredProcedureCommand(IDbConnection, string, int)

Creates a stored procedure IDbCommand from a connection.

CreateTextCommand(DbConnection, string, int)

Creates a text DbCommand from a DbConnection.

CreateTextCommand(IDbConnection, string, int)

Creates a text IDbCommand from a connection.

EnsureOpen(IDbConnection)

If the connection isn't open, opens the connection.
If the connection is in neither open or close, first closes the connection, then opens it.

EnsureOpenAsync(DbConnection, bool, CancellationToken)

If the connection isn't open, opens the connection.
If the connection is in neither open or close, first closes the connection, then opens it.

EnsureOpenAsync(DbConnection, CancellationToken)

If the connection isn't open, opens the connection.
If the connection is in neither open or close, first closes the connection, then opens it.

EnsureOpenAsync(IDbConnection, bool, CancellationToken)

If the connection isn't open, opens the connection.
If the connection is in neither open or close, first closes the connection, then opens it.

EnsureOpenAsync(IDbConnection, CancellationToken)

If the connection isn't open, opens the connection.
If the connection is in neither open or close, first closes the connection, then opens it.

Open(IDbConnectionFactory, Action<IDbConnection>)

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

Open(IDbConnectionPool, Action<IDbConnection, ConnectionState>)

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.

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.

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.

OpenAsync(IDbConnection, bool, CancellationToken)

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

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.

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.

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.

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.

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.

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.

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.

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.

Open<T>(IDbConnectionFactory, Func<IDbConnection, T>)

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

Open<TConnection>(IDbConnectionFactory<TConnection>, Action<TConnection>)

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

Open<T>(IDbConnectionPool, Func<IDbConnection, ConnectionState, T>)

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.

Open<TConnection>(IDbConnectionPool<TConnection>, Action<TConnection, ConnectionState>)

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.

Open<TConnection>(Func<TConnection>, Action<TConnection>)

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

Open<TConnection, T>(IDbConnectionFactory<TConnection>, Func<TConnection, T>)

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

Open<TConnection, T>(IDbConnectionPool<TConnection>, Func<TConnection, ConnectionState, T>)

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.

Open<TConnection, T>(Func<TConnection>, Func<TConnection, T>)

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

StoredProcedure(IDbConnectionFactory, string)

Creates an ExpressiveCommand that calls a stored procedure, creating a new connection from a connection factory for every execution.

StoredProcedure(IDbConnectionPool, string)

Creates an ExpressiveCommand that calls a stored procedure, taking its connections from a connection pool.

StoredProcedure(DbConnection, string)

Creates an ExpressiveDbCommand that calls a stored procedure on the given connection.

StoredProcedure(DbTransaction, string)

Creates an ExpressiveDbCommand that calls a stored procedure within the given transaction.

StoredProcedure(IDbConnection, string)

Creates an ExpressiveCommand that calls a stored procedure on the given connection.

StoredProcedure(IDbTransaction, string)

Creates an ExpressiveCommand that calls a stored procedure within the given transaction.

StoredProcedure(Func<IDbConnection>, string)

Creates an ExpressiveCommand that calls a stored procedure, invoking a function to create a new connection for every execution.

StoredProcedure<TConnection>(IDbConnectionFactory<TConnection>, string)

Creates an ExpressiveDbCommand that calls a stored procedure, creating a new connection from a connection factory for every execution.

StoredProcedure<TConnection>(IDbConnectionPool<TConnection>, string)

Creates an ExpressiveDbCommand that calls a stored procedure, taking its connections from a connection pool.

StoredProcedure<TConnection>(Func<TConnection>, string)

Creates an ExpressiveDbCommand that calls a stored procedure, invoking a function to create a new connection for every execution.

Using(IDbConnectionFactory, Action<IDbConnection>)

Creates a connection from the factory, invokes the action, and then disposes the connection. The connection is not opened by this method.

Using(IDbConnectionPool, Action<IDbConnection>)

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

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.

Using<T>(IDbConnectionFactory, Func<IDbConnection, T>)

Creates a connection from the factory, invokes the action, and then disposes the connection. The connection is not opened by this method.

Using<TConn>(IDbConnectionFactory<TConn>, Action<TConn>)

Creates a connection from the factory, invokes the action, and then disposes the connection. The connection is not opened by this method.

Using<T>(IDbConnectionPool, Func<IDbConnection, T>)

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.

Using<TConn>(IDbConnectionPool<TConn>, Action<TConn>)

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.

Using<TConn>(Func<TConn>, Action<TConn>)

Invokes the function to create a connection, invokes the action, and then disposes the connection. The connection is not opened by this method.

Using<TConn, T>(IDbConnectionFactory<TConn>, Func<TConn, T>)

Creates a connection from the factory, invokes the action, and then disposes the connection. The connection is not opened by this method.

Using<TConn, T>(IDbConnectionPool<TConn>, Func<TConn, T>)

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.

Using<TConn, T>(Func<TConn>, Func<TConn, T>)

Invokes the function to create a connection, invokes the action, and then disposes the connection. The connection is not opened by this method.