Method Command
- Namespace
- Open.Database.Extensions
- Assembly
- Open.Database.Extensions.Core.dll
Command(IDbConnection, string, CommandType)
Creates an ExpressiveCommand that executes on the given connection.
public static ExpressiveCommand Command(this IDbConnection connection, string command, CommandType type = CommandType.Text)
Parameters
connectionIDbConnectionThe connection to execute on. It is opened only if it is closed, closed again afterwards if the command opened it, and never disposed.
commandstringThe command text, or the stored procedure name when
typeis StoredProcedure.typeCommandTypeThe command type. The default is Text.
Returns
- ExpressiveCommand
A new ExpressiveCommand to configure with parameters and then execute.
Examples
int rows = connection
.Command("UPDATE Customers SET Region = @region WHERE Id = @id")
.AddParam("region", "West")
.AddParam("id", 42)
.ExecuteNonQuery();
Remarks
The command is not validated against the database when it is created; problems with the SQL surface as provider exceptions when it is executed. A command created from a connection supports one execution at a time.
Exceptions
- ArgumentNullException
connectionorcommandis null.- ArgumentException
commandis empty or white space.
- See Also
Command(IDbTransaction, string, CommandType)
Creates an ExpressiveCommand that executes within the given transaction.
public static ExpressiveCommand Command(this IDbTransaction transaction, string command, CommandType type = CommandType.Text)
Parameters
transactionIDbTransactionThe transaction to execute in. The command runs on the transaction's Connection.
commandstringThe command text, or the stored procedure name when
typeis StoredProcedure.typeCommandTypeThe command type. The default is Text.
Returns
- ExpressiveCommand
A new ExpressiveCommand to configure with parameters and then execute.
Exceptions
- ArgumentNullException
transactionorcommandis null.- ArgumentException
commandis empty or white space.
Command(DbConnection, string, CommandType)
Creates an ExpressiveDbCommand that executes on the given connection.
public static ExpressiveDbCommand Command(this DbConnection connection, string command, CommandType type = CommandType.Text)
Parameters
connectionDbConnectionThe connection to execute on. It is opened only if it is closed, closed again afterwards if the command opened it, and never disposed.
commandstringThe command text, or the stored procedure name when
typeis StoredProcedure.typeCommandTypeThe command type. The default is Text.
Returns
- ExpressiveDbCommand
A new ExpressiveDbCommand to configure with parameters and then execute.
Exceptions
- ArgumentNullException
connectionorcommandis null.- ArgumentException
commandis empty or white space.
Command(DbTransaction, string, CommandType)
Creates an ExpressiveDbCommand that executes within the given transaction.
public static ExpressiveDbCommand Command(this DbTransaction transaction, string command, CommandType type = CommandType.Text)
Parameters
transactionDbTransactionThe transaction to execute in. The command runs on the transaction's Connection.
commandstringThe command text, or the stored procedure name when
typeis StoredProcedure.typeCommandTypeThe command type. The default is Text.
Returns
- ExpressiveDbCommand
A new ExpressiveDbCommand to configure with parameters and then execute.
Exceptions
- ArgumentNullException
transactionorcommandis null.- ArgumentException
commandis empty or white space.
Command(IDbConnectionFactory, string, CommandType)
Creates an ExpressiveCommand that creates a new connection from a connection factory for every execution.
public static ExpressiveCommand Command(this IDbConnectionFactory connectionSource, string command, CommandType type = CommandType.Text)
Parameters
connectionSourceIDbConnectionFactoryThe factory that creates the connections. Each execution creates a connection, opens it if needed, and disposes it when finished.
commandstringThe command text, or the stored procedure name when
typeis StoredProcedure.typeCommandTypeThe command type. The default is Text.
Returns
- ExpressiveCommand
A new ExpressiveCommand to configure with parameters and then execute.
Exceptions
- ArgumentNullException
connectionSourceorcommandis null.- ArgumentException
commandis empty or white space.
- See Also
Command(IDbConnectionPool, string, CommandType)
Creates an ExpressiveCommand that takes its connections from a connection pool.
public static ExpressiveCommand Command(this IDbConnectionPool connectionSource, string command, CommandType type = CommandType.Text)
Parameters
connectionSourceIDbConnectionPoolThe pool to take connections from. Each execution takes one, opens it if needed, and gives it back when finished.
commandstringThe command text, or the stored procedure name when
typeis StoredProcedure.typeCommandTypeThe command type. The default is Text.
Returns
- ExpressiveCommand
A new ExpressiveCommand to configure with parameters and then execute.
Exceptions
- ArgumentNullException
connectionSourceorcommandis null.- ArgumentException
commandis empty or white space.
Command<TConnection>(IDbConnectionFactory<TConnection>, string, CommandType)
Creates an ExpressiveDbCommand that creates a new connection from a connection factory for every execution.
public static ExpressiveDbCommand Command<TConnection>(this IDbConnectionFactory<TConnection> connectionSource, string command, CommandType type = CommandType.Text) where TConnection : DbConnection
Parameters
connectionSourceIDbConnectionFactory<TConnection>The factory that creates the connections. Each execution creates a connection, opens it if needed, and disposes it when finished.
commandstringThe command text, or the stored procedure name when
typeis StoredProcedure.typeCommandTypeThe command type. The default is Text.
Returns
- ExpressiveDbCommand
A new ExpressiveDbCommand to configure with parameters and then execute.
Type Parameters
TConnectionThe connection type.
Exceptions
- ArgumentNullException
connectionSourceorcommandis null.- ArgumentException
commandis empty or white space.
Command<TConnection>(IDbConnectionPool<TConnection>, string, CommandType)
Creates an ExpressiveDbCommand that takes its connections from a connection pool.
public static ExpressiveDbCommand Command<TConnection>(this IDbConnectionPool<TConnection> connectionSource, string command, CommandType type = CommandType.Text) where TConnection : DbConnection
Parameters
connectionSourceIDbConnectionPool<TConnection>The pool to take connections from. Each execution takes one, opens it if needed, and gives it back when finished.
commandstringThe command text, or the stored procedure name when
typeis StoredProcedure.typeCommandTypeThe command type. The default is Text.
Returns
- ExpressiveDbCommand
A new ExpressiveDbCommand to configure with parameters and then execute.
Type Parameters
TConnectionThe connection type.
Exceptions
- ArgumentNullException
connectionSourceorcommandis null.- ArgumentException
commandis empty or white space.
Command(Func<IDbConnection>, string, CommandType)
Creates an ExpressiveCommand that invokes a function to create a new connection for every execution.
public static ExpressiveCommand Command(this Func<IDbConnection> connectionSource, string command, CommandType type = CommandType.Text)
Parameters
connectionSourceFunc<IDbConnection>The function that creates the connections. Each execution invokes it, opens the connection if needed, and disposes it when finished.
commandstringThe command text, or the stored procedure name when
typeis StoredProcedure.typeCommandTypeThe command type. The default is Text.
Returns
- ExpressiveCommand
A new ExpressiveCommand to configure with parameters and then execute.
Exceptions
- ArgumentNullException
commandis null.- ArgumentException
commandis empty or white space.
Command<TConnection>(Func<TConnection>, string, CommandType)
Creates an ExpressiveDbCommand that invokes a function to create a new connection for every execution.
public static ExpressiveDbCommand Command<TConnection>(this Func<TConnection> connectionSource, string command, CommandType type = CommandType.Text) where TConnection : DbConnection
Parameters
connectionSourceFunc<TConnection>The function that creates the connections. Each execution invokes it, opens the connection if needed, and disposes it when finished.
commandstringThe command text, or the stored procedure name when
typeis StoredProcedure.typeCommandTypeThe command type. The default is Text.
Returns
- ExpressiveDbCommand
A new ExpressiveDbCommand to configure with parameters and then execute.
Type Parameters
TConnectionThe connection type.
Examples
// A new connection is created, opened, and disposed for every execution.
int count = createConnection
.Command("SELECT COUNT(*) FROM Customers")
.ExecuteScalar<int>();
Exceptions
- ArgumentNullException
commandis null.- ArgumentException
commandis empty or white space.