Table of Contents

Method Command

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

Command(SqlConnection, string, CommandType)

Creates an ExpressiveSqlCommand that executes on the given connection.

public static ExpressiveSqlCommand Command(this SqlConnection connection, string command, CommandType type = CommandType.Text)

Parameters

connection SqlConnection

The connection to execute on. It is opened only if it is closed, closed again afterwards if the command opened it, and never disposed.

command string

The command text, or the stored procedure name when type is StoredProcedure.

type CommandType

The command type. The default is Text.

Returns

ExpressiveSqlCommand

A new ExpressiveSqlCommand to configure with parameters and then execute.

Exceptions

ArgumentNullException

connection or command is null.

ArgumentException

command is empty or white space.

Command(SqlTransaction, string, CommandType)

Creates an ExpressiveSqlCommand that executes within the given transaction.

public static ExpressiveSqlCommand Command(this SqlTransaction transaction, string command, CommandType type = CommandType.Text)

Parameters

transaction SqlTransaction

The transaction to execute in. The command runs on the transaction's Connection.

command string

The command text, or the stored procedure name when type is StoredProcedure.

type CommandType

The command type. The default is Text.

Returns

ExpressiveSqlCommand

A new ExpressiveSqlCommand to configure with parameters and then execute.

Exceptions

ArgumentNullException

transaction or command is null.

ArgumentException

command is empty or white space.

Command(IDbConnectionFactory<SqlConnection>, string, CommandType)

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

public static ExpressiveSqlCommand Command(this IDbConnectionFactory<SqlConnection> connectionSource, string command, CommandType type = CommandType.Text)

Parameters

connectionSource IDbConnectionFactory<SqlConnection>

The factory that creates the connections. Each execution creates a connection, opens it if needed, and disposes it when finished.

command string

The command text, or the stored procedure name when type is StoredProcedure.

type CommandType

The command type. The default is Text.

Returns

ExpressiveSqlCommand

A new ExpressiveSqlCommand to configure with parameters and then execute.

Exceptions

ArgumentNullException

connectionSource or command is null.

ArgumentException

command is empty or white space.

Command(IDbConnectionPool<SqlConnection>, string, CommandType)

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

public static ExpressiveSqlCommand Command(this IDbConnectionPool<SqlConnection> connectionSource, string command, CommandType type = CommandType.Text)

Parameters

connectionSource IDbConnectionPool<SqlConnection>

The pool to take connections from. Each execution takes one, opens it if needed, and gives it back when finished.

command string

The command text, or the stored procedure name when type is StoredProcedure.

type CommandType

The command type. The default is Text.

Returns

ExpressiveSqlCommand

A new ExpressiveSqlCommand to configure with parameters and then execute.

Exceptions

ArgumentNullException

connectionSource or command is null.

ArgumentException

command is empty or white space.

Command(Func<SqlConnection>, string, CommandType)

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

public static ExpressiveSqlCommand Command(this Func<SqlConnection> connectionSource, string command, CommandType type = CommandType.Text)

Parameters

connectionSource Func<SqlConnection>

The function that creates the connections. Each execution invokes it, opens the connection if needed, and disposes it when finished.

command string

The command text, or the stored procedure name when type is StoredProcedure.

type CommandType

The command type. The default is Text.

Returns

ExpressiveSqlCommand

A new ExpressiveSqlCommand to configure with parameters and then execute.

Exceptions

ArgumentNullException

connectionSource or command is null.

ArgumentException

command is empty or white space.