Class ExpressiveDbCommandBase<TConnection, TCommand, TReader, TDbType, TThis>
- Namespace
- Open.Database.Extensions
- Assembly
- Open.Database.Extensions.Core.dll
An base class for executing commands on a database using best practices and simplified expressive syntax. Includes methods for use with DbConnection and DbCommand types.
public abstract class ExpressiveDbCommandBase<TConnection, TCommand, TReader, TDbType, TThis> : ExpressiveCommandBase<TConnection, TCommand, TReader, TDbType, TThis>, IExecuteCommand<TCommand>, IExecuteCommand, IExecuteReaderAsync<TReader>, IExecuteReaderAsync, IExecuteReader<TReader>, IExecuteReader where TConnection : DbConnection where TCommand : DbCommand where TReader : DbDataReader where TDbType : struct where TThis : ExpressiveDbCommandBase<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 this class in order to facilitate proper expressive notation.
- Inheritance
-
ExpressiveCommandBase<TConnection, TCommand, TReader, TDbType, TThis>ExpressiveDbCommandBase<TConnection, TCommand, TReader, TDbType, TThis>
- Implements
-
IExecuteCommand<TCommand>IExecuteReaderAsync<TReader>IExecuteReader<TReader>
- Derived
- Inherited Members
- Extension Methods
Constructors
- ExpressiveDbCommandBase(IDbConnectionFactory<TConnection>, CommandType, string, IEnumerable<Param>?)
Constructs a an expressive command.
- ExpressiveDbCommandBase(IDbConnectionPool<TConnection>, CommandType, string, IEnumerable<Param>?)
Constructs a an expressive command.
- ExpressiveDbCommandBase(IDbTransaction, CommandType, string, IEnumerable<Param>?)
Constructs a an expressive command.
- ExpressiveDbCommandBase(Func<TConnection>, CommandType, string, IEnumerable<Param>?)
Constructs a an expressive command.
- ExpressiveDbCommandBase(TConnection, CommandType, string, IEnumerable<Param>?)
Constructs a an expressive command.
- ExpressiveDbCommandBase(TConnection, IDbTransaction?, CommandType, string, IEnumerable<Param>?)
Constructs a an expressive command.
Properties
- UseAsyncRead
By default (false), for async methods, the underlying iteration operation for a reader will be .Read() whenever possible. If set to true, .ReadAsync() will be used. Using .ReadAsync() can introduce unexpected latency and additional CPU overhead. This should only be set to true if there is a clear reason why and should be profiled before and after.
Methods
- EnableAsyncRead(bool)
Sets the UseAsyncRead value.
- ExecuteNonQueryAsync()
Calls ExecuteNonQueryAsync on the underlying command.
- ExecuteScalarAsync()
Calls ExecuteScalarAsync on the underlying command.
- ExecuteScalarAsync<T>()
Asynchronously executes scalar on the underlying command and casts to the expected type.
- ExecuteScalarAsync<T>(Func<object?, ValueTask<T>>)
Asynchronously executes scalar on the underlying command.
- ExecuteScalarAsync<T>(Func<object?, T>)
Asynchronously executes scalar on the underlying command.
- FirstOrdinalResultsAsync()
Reads the first column from every record and returns the results as a list.. DBNull values are converted to null.
- FirstOrdinalResultsAsync<T0>()
Reads the first column from every record.. DBNull values are converted to null.
- ResultsAsync<T>()
Asynchronously returns all records and iteratively attempts to map the fields to type T.
- ResultsAsync<T>(params IEnumerable<KeyValuePair<string, string?>>)
Asynchronously returns all records and iteratively attempts to map the fields to type T.
- ResultsAsync<T>(params IEnumerable<(string Field, string? Column)>)
Asynchronously returns all records and iteratively attempts to map the fields to type T.
- RetrieveAsync()
Asynchronously iterates all records within the first result set using an IDataReader and returns the results.
- RetrieveAsync(IEnumerable<int>)
Asynchronously iterates all records within the current result set using an IDataReader and returns the desired results.
- RetrieveAsync(IEnumerable<string>, bool)
Iterates all records within the first result set using an IDataReader and returns the desired results as a list of Dictionaries containing only the specified column values.
- RetrieveAsync(int, params IEnumerable<int>)
Asynchronously iterates all records within the current result set using an IDataReader and returns the desired results.
- RetrieveAsync(string, params IEnumerable<string>)
Iterates all records within the current result set using an IDataReader and returns the desired results.
- TakeAsync<T>(Func<IDataRecord, T>, int, CommandBehavior)
Asynchronously iterates a IDataReader and returns the each result until the count is met.
- ToListAsync<T>(Func<IDataRecord, T>, CommandBehavior)
Asynchronously returns all records via a transform function.