Class ExpressiveSqlCommand
- Namespace
- Open.Database.Extensions
- Assembly
- Open.Database.Extensions.MSSqlClient.dll
A deferred, fluent command for running SQL through a SqlConnection, SqlTransaction, connection factory, or connection pool, with parameters typed by SqlDbType. Nothing touches the database until an execute method is called.
public class ExpressiveSqlCommand : ExpressiveDbCommandBase<SqlConnection, SqlCommand, SqlDataReader, SqlDbType, ExpressiveSqlCommand>, IExecuteCommand<SqlCommand>, IExecuteCommand, IExecuteReaderAsync<SqlDataReader>, IExecuteReaderAsync, IExecuteReader<SqlDataReader>, IExecuteReader
- Inheritance
-
ExpressiveSqlCommand
- Implements
- Inherited Members
Remarks
Create one with the Command and StoredProcedure extension methods in SqlConnectionExtensions, add parameters with AddParam, optionally set a timeout and cancellation token, then run it with one of the execute methods (for example ExecuteNonQuery, ExecuteScalar, ExecuteReader, or Map<T>()).
Connections follow the same "get in, get out" model as ExpressiveDbCommand: each execution takes a connection, opens it only if needed, runs the command, and releases the connection. A connection supplied directly is closed again only if this execution opened it and is never disposed; a connection from a factory is disposed, and one from a pool is given back.
Constructors
- ExpressiveSqlCommand(SqlConnection, CommandType, string, IEnumerable<Param>?)
Constructs a command that executes on an existing connection.
- ExpressiveSqlCommand(SqlConnection, IDbTransaction?, CommandType, string, IEnumerable<Param>?)
Constructs a command that executes on an existing connection, optionally within a transaction.
- ExpressiveSqlCommand(IDbConnectionFactory<SqlConnection>, CommandType, string, IEnumerable<Param>?)
Constructs a command that creates a new connection from a connection factory for each execution.
- ExpressiveSqlCommand(IDbConnectionPool<SqlConnection>, CommandType, string, IEnumerable<Param>?)
Constructs a command that takes its connections from a connection pool.
- ExpressiveSqlCommand(IDbTransaction, CommandType, string, IEnumerable<Param>?)
Constructs a command that executes within a transaction, on the transaction's connection.
Methods
- AddParams(SqlCommand)
Handles adding the list of parameters to a new command.