Class ExpressiveDbCommand
- Namespace
- Open.Database.Extensions
- Assembly
- Open.Database.Extensions.Core.dll
A deferred, fluent command for running SQL through any DbConnection, DbTransaction, connection factory, or connection pool, whose callbacks receive the DbCommand and DbDataReader.
public class ExpressiveDbCommand : ExpressiveDbCommandBase<DbConnection, DbCommand, DbDataReader, DbType, ExpressiveDbCommand>, IExecuteCommand<DbCommand>, IExecuteCommand, IExecuteReaderAsync<DbDataReader>, IExecuteReaderAsync, IExecuteReader<DbDataReader>, IExecuteReader
- Inheritance
-
ExpressiveDbCommand
- Implements
- Inherited Members
- Extension Methods
Examples
List<Post> posts = await connection
.Command("SELECT Id, Title FROM Posts WHERE AuthorId = @authorId")
.AddParam(authorId)
.Map<Post>()
.ToListAsync(cancellationToken);
Remarks
Create one with the Command and StoredProcedure extension methods in ConnectionExtensions, add parameters with AddParam, optionally set a timeout and cancellation token, then run it with one of the execute methods.
Connection ownership is as for ExpressiveCommand: a connection supplied directly is closed again only if this execution opened it and is never disposed; one from a factory is disposed, and one from a pool is given back.
Constructors
- ExpressiveDbCommand(IDbConnectionFactory<DbConnection>, CommandType, string, IEnumerable<Param>?)
Initializes a new instance that creates a new connection from a connection factory for each execution.
- ExpressiveDbCommand(IDbConnectionPool<DbConnection>, CommandType, string, IEnumerable<Param>?)
Initializes a new instance that takes its connections from a connection pool.
- ExpressiveDbCommand(DbConnection, CommandType, string, IEnumerable<Param>?)
Initializes a new instance that executes on an existing connection.
- ExpressiveDbCommand(DbConnection, IDbTransaction?, CommandType, string, IEnumerable<Param>?)
Initializes a new instance that executes on an existing connection, optionally within a transaction.
- ExpressiveDbCommand(IDbTransaction, CommandType, string, IEnumerable<Param>?)
Initializes a new instance that executes within a transaction, on the transaction's connection.
- ExpressiveDbCommand(Func<DbConnection>, CommandType, string, IEnumerable<Param>?)
Initializes a new instance that invokes a function to create a new connection for each execution.
Methods
- AddParams(DbCommand)
Handles adding the list of parameters to a new command.
- GetProcedureParameterNames(DbConnection, string)
Gets the parameter names a stored procedure declares through the ADO.NET schema collection
ProcedureParameters, so parameters added withAddParam(value)find their real names on any provider that supports it (SQL Server does).
- GetProcedureParameterNamesAsync(DbConnection, string, CancellationToken)
Asynchronously gets the parameter names a stored procedure declares through the ADO.NET schema collection
ProcedureParameters.