Table of Contents

Class SqlConnectionExtensions

Namespace
Open.Database.Extensions
Assembly
Open.Database.Extensions.MSSqlClient.dll

Extension methods that create an ExpressiveSqlCommand or a SqlCommand from a connection, transaction, connection factory, connection pool, or factory function.

public static class SqlConnectionExtensions
Inheritance
SqlConnectionExtensions
Inherited Members

Remarks

The Command and StoredProcedure extension methods are the entry points to the expressive API for SQL Server. They create an ExpressiveSqlCommand from a SqlConnection, a SqlTransaction, 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(SqlConnection, string, CommandType)

Creates an ExpressiveSqlCommand that executes on the given connection.

Command(SqlTransaction, string, CommandType)

Creates an ExpressiveSqlCommand that executes within the given transaction.

Command(IDbConnectionFactory<SqlConnection>, string, CommandType)

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

Command(IDbConnectionPool<SqlConnection>, string, CommandType)

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

Command(Func<SqlConnection>, string, CommandType)

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

CreateCommand(SqlConnection, CommandType, string, int)

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

CreateStoredProcedureCommand(SqlConnection, string, int)

Creates a stored procedure SqlCommand from a connection.

CreateTextCommand(SqlConnection, string, int)

Creates a text SqlCommand from a connection.

StoredProcedure(SqlConnection, string)

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

StoredProcedure(SqlTransaction, string)

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

StoredProcedure(IDbConnectionFactory<SqlConnection>, string)

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

StoredProcedure(IDbConnectionPool<SqlConnection>, string)

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

StoredProcedure(Func<SqlConnection>, string)

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