Class DataRequestBase<TConnection, TModel>
Serves as the base class for implementing database requests with a specific connection type and return model.
public abstract class DataRequestBase<TConnection, TModel> : IDataRequest<TConnection, TModel>, IDataRequest
Type Parameters
TConnectionThe type of the database connection.
TModelThe type of the model to be returned by the request.
- Inheritance
-
DataRequestBase<TConnection, TModel>
- Implements
-
IDataRequest<TConnection, TModel>
- Derived
- Inherited Members
- Extension Methods
Properties
Command
Gets the command definition used for executing the request.
public CommandDefinition Command { get; protected init; }
Property Value
- CommandDefinition
The command definition used for executing the request.
CorrelationId
Gets the optional correlation identifier for tracking related requests.
public string? CorrelationId { get; set; }
Property Value
- string
The optional correlation identifier for tracking related requests.
CreatedAt
Gets the timestamp when the request was created.
public DateTimeOffset CreatedAt { get; }
Property Value
- DateTimeOffset
The timestamp when the request was created.
Metadata
Gets additional metadata associated with the request.
public IDictionary<string, object>? Metadata { get; set; }
Property Value
- IDictionary<string, object>
Additional metadata associated with the request.
Parameters
Gets the parameters associated with the request.
public DynamicParameters Parameters { get; }
Property Value
- DynamicParameters
The parameters associated with the request.
RequestId
Gets the unique request identifier.
public string RequestId { get; }
Property Value
- string
The unique request identifier.
RequestType
Gets the request type name.
public string RequestType { get; }
Property Value
- string
The request type name.
ResolveAsync
Gets the function responsible for resolving the request result using the provided connection.
public Func<TConnection, Task<TModel>> ResolveAsync { get; protected init; }
Property Value
- Func<TConnection, Task<TModel>>
The function responsible for resolving the request result using the provided connection.
Methods
CreateCommand(string, DynamicParameters?, IDbTransaction?, int?, CommandType?, CancellationToken)
Creates a command definition for the request.
protected CommandDefinition CreateCommand(string commandText, DynamicParameters? parameters = null, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default)
Parameters
commandTextstringThe SQL command text.
parametersDynamicParametersThe parameters for the command (optional).
transactionIDbTransactionThe transaction for this command to participate in.
commandTimeoutint?The timeout (in seconds) for this command.
commandTypeCommandType?The CommandType for this command.
cancellationTokenCancellationTokenThe cancellation token for this command.
Returns
- CommandDefinition
A Dapper.CommandDefinition instance representing the request.
ExecuteNonQueryAsync(IDbConnection, Action<DbCommand>)
Executes this request without runtime parameter discovery or generated command initialization.
protected Task<int> ExecuteNonQueryAsync(IDbConnection connection, Action<DbCommand> bind)
Parameters
connectionIDbConnectionThe existing provider connection.
bindAction<DbCommand>Binds the operation's known parameters from their current request values.
Returns
Remarks
The request's command text, transaction, timeout, command type and cancellation token are preserved.
ExecuteScalarAsync(IDbConnection, Action<DbCommand>)
Reads this request's scalar result without runtime parameter discovery.
protected Task<object?> ExecuteScalarAsync(IDbConnection connection, Action<DbCommand> bind)
Parameters
connectionIDbConnectionThe existing provider connection.
bindAction<DbCommand>Binds the operation's known parameters from their current request values.
Returns
ReadRowsAsync<TRow>(IDbConnection, Action<DbCommand>, Func<DbDataReader, TRow>)
Buffers rows with an explicit ordinal projection instead of runtime row mapping.
protected Task<IEnumerable<TRow>> ReadRowsAsync<TRow>(IDbConnection connection, Action<DbCommand> bind, Func<DbDataReader, TRow> materialize)
Parameters
connectionIDbConnectionThe existing provider connection.
bindAction<DbCommand>Binds the operation's known parameters from their current request values.
materializeFunc<DbDataReader, TRow>Reads one current row using the operation's fixed projection.
Returns
- Task<IEnumerable<TRow>>
The fully buffered rows after reader cleanup.
Type Parameters
TRowThe operation's statically known row type.
Remarks
A borrowed open connection and transaction remain caller-owned. A connection opened for this request is closed afterward.