Class ExpressiveCommandBase<TConnection, TCommand, TReader, TDbType, TThis>
- Namespace
- Open.Database.Extensions
- Assembly
- Open.Database.Extensions.Core.dll
Represents the base class of the expressive commands, for use with IDbConnection and IDbCommand types.
public abstract class ExpressiveCommandBase<TConnection, TCommand, TReader, TDbType, TThis> : IExecuteCommand<TCommand>, IExecuteCommand, IExecuteReader<TReader>, IExecuteReader where TConnection : class, IDbConnection where TCommand : class, IDbCommand where TReader : class, IDataReader where TDbType : struct where TThis : ExpressiveCommandBase<TConnection, TCommand, TReader, TDbType, TThis>
Type Parameters
TConnectionThe type of the connection to be used.
TCommandThe type of the commands generated by the connection.
TReaderThe type of reader created by the command.
TDbTypeThe DB type enum to use for parameters.
TThisThe type of the derived class, so that the chaining methods return it.
- Inheritance
-
ExpressiveCommandBase<TConnection, TCommand, TReader, TDbType, TThis>
- Implements
-
IExecuteCommand<TCommand>IExecuteReader<TReader>
- Derived
- Inherited Members
- Extension Methods
Remarks
For a command you run more than once, use DbQuery. This builder is for a command you build and run once.
A command whose text is a string literal sends an input parameter's name written without its @ under the text's own spelling; a parameter that is not an input keeps the name it was added with, as the caller reads it back by that name.
Constructors
- ExpressiveCommandBase(IDbConnectionFactory<TConnection>, CommandType, string, IEnumerable<Param>?)
Initializes a new instance that creates a new connection from a connection factory for each execution.
- ExpressiveCommandBase(IDbConnectionPool<TConnection>, CommandType, string, IEnumerable<Param>?)
Initializes a new instance that takes its connections from a connection pool.
- ExpressiveCommandBase(IDbTransaction, CommandType, string, IEnumerable<Param>?)
Initializes a new instance that executes within a transaction, on the transaction's connection.
- ExpressiveCommandBase(Func<TConnection>, CommandType, string, IEnumerable<Param>?)
Initializes a new instance that invokes a function to create a new connection for each execution.
- ExpressiveCommandBase(TConnection, CommandType, string, IEnumerable<Param>?)
Initializes a new instance that executes on an existing connection.
- ExpressiveCommandBase(TConnection, IDbTransaction?, CommandType, string, IEnumerable<Param>?)
Initializes a new instance that executes on an existing connection, optionally within a transaction.
Properties
- CancellationToken
Gets or sets the cancellation token used with the methods that support one.
- Command
Gets or sets the command text, or the stored procedure name when Type is StoredProcedure.
- ConnectionProvider
Gets the pool that connections are taken from.
- Params
Gets the parameters to apply to the command before execution.
- Timeout
Gets or sets the command timeout, in seconds.
- Transaction
Gets the transaction the command runs in, or null when it was not given one.
Methods
- AddParam(Param)
Adds a parameter to the params list.
- AddParam(string, char, TDbType?, ParameterDirection)
Adds a parameter with a char value, sent as a character.
- AddParam(string, char, TDbType, ParameterDirection)
Adds a parameter with a char value, sent as a character, and a required database type.
- AddParam(string, ParameterDirection)
Adds a parameter with no value and the direction given.
- AddParam(string, int, TDbType?, ParameterDirection)
Adds a parameter with an int value.
- AddParam(string, int, TDbType, ParameterDirection)
Adds a parameter with an int value and a required database type.
- AddParam(string, long, TDbType?, ParameterDirection)
Adds a parameter with a long value.
- AddParam(string, long, TDbType, ParameterDirection)
Adds a parameter with a long value and a required database type.
- AddParam(string, object?, ParameterDirection)
Adds a parameter to the params list.
- AddParam(string, object?, TDbType, ParameterDirection)
Adds a parameter to the params list.
- AddParam(string, string?)
Adds an input parameter with a string value, named as you write it.
- AddParam(string, string?, TDbType?, ParameterDirection)
Adds a parameter to the params list.
- AddParam(string, string?, TDbType, ParameterDirection)
Adds a parameter to the params list.
- AddParam(string, TDbType, ParameterDirection)
Adds a parameter to the params list.
- AddParamIf(bool, string, char, TDbType?, ParameterDirection)
Conditionally adds a parameter to the params list.
- AddParamIf(bool, string, char, TDbType, ParameterDirection)
Conditionally adds a parameter to the params list.
- AddParamIf(bool, string, ParameterDirection)
Conditionally adds a parameter to the params list.
- AddParamIf(bool, string, int, TDbType?, ParameterDirection)
Conditionally adds a parameter to the params list.
- AddParamIf(bool, string, int, TDbType, ParameterDirection)
Conditionally adds a parameter to the params list.
- AddParamIf(bool, string, long, TDbType?, ParameterDirection)
Conditionally adds a parameter to the params list.
- AddParamIf(bool, string, long, TDbType, ParameterDirection)
Conditionally adds a parameter to the params list.
- AddParamIf(bool, string, object?, ParameterDirection)
Conditionally adds a parameter to the params list.
- AddParamIf(bool, string, object?, TDbType, ParameterDirection)
Conditionally adds a parameter to the params list.
- AddParamIf(bool, string, string?)
Conditionally adds an input parameter with a string value, named as you write it.
- AddParamIf(bool, string, string?, TDbType, ParameterDirection)
Conditionally adds a parameter to the params list.
- AddParamIf(bool, string, TDbType, ParameterDirection)
Conditionally adds a parameter to the params list.
- AddParamIf<T>(bool, string, T?, ParameterDirection)
Conditionally adds a parameter to the params list.
- AddParamIf<T>(bool, string, T?, TDbType?, ParameterDirection)
Conditionally adds a parameter to the params list.
- AddParamIf<T>(bool, string, T?, TDbType, ParameterDirection)
Conditionally adds a parameter to the params list.
- AddParamIf<T>(bool, T, string?)
Conditionally adds an input parameter whose name is taken from the argument expression. See AddParam<T>(T, string?).
- AddParam<T>(string, T?, TDbType?, ParameterDirection)
Adds a parameter to the params list.
- AddParam<T>(string, T?, TDbType, ParameterDirection)
Adds a parameter to the params list.
- AddParam<T>(T, string?)
Adds an input parameter whose name is taken from the argument expression:
AddParam(filter.AuthorId)adds a parameter named forAuthorId.
- AddParams(TCommand)
Handles adding the list of parameters to a new command.
- AddParams<T>(T)
Adds the public properties and fields of
sourceas parameters, under the real names the stored procedure declares for them (AuthorIdas@author_id).
- AddReturnParam(string)
Adds a return parameter to the params list.
- AddReturnParam(string, TDbType)
Adds a return parameter to the params list.
- EnsureReaderType<TActual>(TActual)
Casts a reader to the expected reader type.
- ExecuteAsync(Func<TCommand, ValueTask>)
Asynchronously creates a command of type
TCommandand passes it tohandler.
- ExecuteAsync<T>(Func<TCommand, ValueTask<T>>)
Asynchronously creates a command of type
TCommandand passes it totransform, returning its result.
- ExecuteReaderAsync(Action<TReader>, CommandBehavior, CancellationToken)
Executes a reader on the command with a handler action.
- ExecuteReaderAsync(Action<TReader>, CancellationToken)
Executes a reader on the command with a handler action, and a token.
- ExecuteReaderAsync(Func<TReader, ValueTask>, CommandBehavior, CancellationToken)
Executes a reader on the command with an asynchronous handler function.
- ExecuteReaderAsync(Func<TReader, ValueTask>, CancellationToken)
Executes a reader on the command with an asynchronous handler function, and a token.
- ExecuteReaderAsync<T>(Func<TReader, ValueTask<T>>, CommandBehavior, CancellationToken)
Executes a reader on the command with an asynchronous transform function.
- ExecuteReaderAsync<T>(Func<TReader, ValueTask<T>>, CancellationToken)
Executes a reader on the command with an asynchronous transform function, and a token.
- ExecuteReaderAsync<T>(Func<TReader, T>, CommandBehavior, CancellationToken)
Executes a reader on the command with a transform function.
- ExecuteReaderAsync<T>(Func<TReader, T>, CancellationToken)
Executes a reader on the command with a transform function, and a token.
- ExecuteReaderAsync<TState, TResult>(TState, Func<IDataReader, TState, ValueTask<TResult>>, CommandBehavior, CancellationToken)
Executes a reader on the command, passing
statetotransform.
- ExecuteReaderAsync<TState, TResult>(TState, Func<IDataReader, TState, ValueTask<TResult>>, CancellationToken)
Executes a reader on the command, passing
statetotransform.
- ExecuteReturnAsync(CancellationToken)
Asynchronously executes the command with a return parameter, as ExecuteNonQueryAsync(CancellationToken) does, and returns the value of that parameter.
- ExecuteReturnAsync<T>(CancellationToken)
Asynchronously executes the command with a return parameter, as ExecuteNonQueryAsync(CancellationToken) does, and returns the value of that parameter converted to
T.
- GetProcedureParameterNames(TConnection, string)
Gets the names of the parameters a stored procedure declares, so a parameter added with
AddParam(value)can be matched to the real one.
- GetProcedureParameterNamesAsync(TConnection, string, CancellationToken)
Asynchronously gets the names of the parameters a stored procedure declares. See GetProcedureParameterNames(TConnection, string).
- PrepareCommand(TConnection)
Creates the expected command type from the connection provided.
- SetTimeout(ushort)
Sets the command timeout.
- UseCancellationToken(CancellationToken)
Sets the cancellation token.