methodAsCommand
public static CommandDefinition AsCommand(this ITransactionContext context, string commandText, object? parameters = null, CommandType? commandType = null, CommandFlags flags = CommandFlags.Buffered, int? commandTimeout = null, CancellationToken cancellationToken = default)
Constructs a `CommandDefinition` configured with the active transaction and cancellation token.
- context: this ITransactionContext
- The active transaction context.
- commandText: string
- The SQL command text to execute.
- parameters: object?
- The command parameters, or `null` if none.
- commandType: CommandType?
- The command type interpretation, or `null` for default.
- flags: CommandFlags
- The behavior flags for command execution.
- commandTimeout: int?
- The per-command timeout in seconds, or `null` to use the default.
- cancellationToken: CancellationToken
- A token that can be used to cancel the asynchronous operation.
Retorna: A configured `CommandDefinition` bound to the active transaction.
methodExecuteAsync
public static async Task<int> ExecuteAsync(this ITransactionContext context, string sql, object? param = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default)
Executes a SQL statement within the active transaction context.
- context: this ITransactionContext
- The active transaction context.
- sql: string
- The SQL statement to execute.
- param: object?
- The parameters to pass to the command, or `null` if none.
- commandTimeout: int?
- The command execution timeout in seconds, or `null` to use the default.
- commandType: CommandType?
- The command type interpretation, or `null` for default.
- cancellationToken: CancellationToken
- A token that can be used to cancel the asynchronous operation.
Retorna: A task representing the asynchronous operation. The task result contains the number of rows affected.
methodExecuteReaderAsync
public static async Task<IDataReader> ExecuteReaderAsync(this ITransactionContext context, string sql, object? param = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default)
Executes a query within the active transaction context and returns an `IDataReader`.
- context: this ITransactionContext
- The active transaction context.
- sql: string
- The SQL query to execute.
- param: object?
- The parameters to pass to the query, or `null` if none.
- commandTimeout: int?
- The command execution timeout in seconds, or `null` to use the default.
- commandType: CommandType?
- The command type interpretation, or `null` for default.
- cancellationToken: CancellationToken
- A token that can be used to cancel the asynchronous operation.
Retorna: A task representing the asynchronous operation. The task result contains the `IDataReader`.
methodExecuteScalarAsync<T>
public static async Task<T?> ExecuteScalarAsync<T>(this ITransactionContext context, string sql, object? param = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default)
Executes a query within the active transaction context and returns the first column of the first row.
- context: this ITransactionContext
- The active transaction context.
- sql: string
- The SQL query to execute.
- param: object?
- The parameters to pass to the query, or `null` if none.
- commandTimeout: int?
- The command execution timeout in seconds, or `null` to use the default.
- commandType: CommandType?
- The command type interpretation, or `null` for default.
- cancellationToken: CancellationToken
- A token that can be used to cancel the asynchronous operation.
Retorna: A task representing the asynchronous operation. The task result contains the scalar value, or the default value if the result set is empty.
methodQueryAsync<T>
public static async Task<IEnumerable<T>> QueryAsync<T>(this ITransactionContext context, string sql, object? param = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default)
Executes a query within the active transaction context and returns mapped results.
- context: this ITransactionContext
- The active transaction context.
- sql: string
- The SQL query to execute.
- param: object?
- The parameters to pass to the query, or `null` if none.
- commandTimeout: int?
- The command execution timeout in seconds, or `null` to use the default.
- commandType: CommandType?
- The command type interpretation, or `null` for default.
- cancellationToken: CancellationToken
- A token that can be used to cancel the asynchronous operation.
Retorna: A task representing the asynchronous operation. The task result contains an enumerable sequence of mapped entities.
methodQueryFirstAsync<T>
public static async Task<T> QueryFirstAsync<T>(this ITransactionContext context, string sql, object? param = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default)
Executes a query within the active transaction context and returns the first element.
- context: this ITransactionContext
- The active transaction context.
- sql: string
- The SQL query to execute.
- param: object?
- The parameters to pass to the query, or `null` if none.
- commandTimeout: int?
- The command execution timeout in seconds, or `null` to use the default.
- commandType: CommandType?
- The command type interpretation, or `null` for default.
- cancellationToken: CancellationToken
- A token that can be used to cancel the asynchronous operation.
Retorna: A task representing the asynchronous operation. The task result contains the first matching element.
methodQueryFirstOrDefaultAsync<T>
public static async Task<T?> QueryFirstOrDefaultAsync<T>(this ITransactionContext context, string sql, object? param = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default)
Executes a query within the active transaction context and returns the first element or a default value.
- context: this ITransactionContext
- The active transaction context.
- sql: string
- The SQL query to execute.
- param: object?
- The parameters to pass to the query, or `null` if none.
- commandTimeout: int?
- The command execution timeout in seconds, or `null` to use the default.
- commandType: CommandType?
- The command type interpretation, or `null` for default.
- cancellationToken: CancellationToken
- A token that can be used to cancel the asynchronous operation.
Retorna: A task representing the asynchronous operation. The task result contains the first matching element, or the default value if none was found.
methodQueryMultipleAsync
public static async Task<SqlMapper.GridReader> QueryMultipleAsync(this ITransactionContext context, string sql, object? param = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default)
Executes a multiple-result-set query within the active transaction context.
- context: this ITransactionContext
- The active transaction context.
- sql: string
- The SQL query returning multiple result sets to execute.
- param: object?
- The parameters to pass to the query, or `null` if none.
- commandTimeout: int?
- The command execution timeout in seconds, or `null` to use the default.
- commandType: CommandType?
- The command type interpretation, or `null` for default.
- cancellationToken: CancellationToken
- A token that can be used to cancel the asynchronous operation.
Retorna: A task representing the asynchronous operation. The task result contains a `SqlMapper.GridReader` for reading multiple results.
methodQuerySingleAsync<T>
public static async Task<T> QuerySingleAsync<T>(this ITransactionContext context, string sql, object? param = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default)
Executes a query within the active transaction context and returns a single element.
- context: this ITransactionContext
- The active transaction context.
- sql: string
- The SQL query to execute.
- param: object?
- The parameters to pass to the query, or `null` if none.
- commandTimeout: int?
- The command execution timeout in seconds, or `null` to use the default.
- commandType: CommandType?
- The command type interpretation, or `null` for default.
- cancellationToken: CancellationToken
- A token that can be used to cancel the asynchronous operation.
Retorna: A task representing the asynchronous operation. The task result contains the single matching element.
methodQuerySingleOrDefaultAsync<T>
public static async Task<T?> QuerySingleOrDefaultAsync<T>(this ITransactionContext context, string sql, object? param = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default)
Executes a query within the active transaction context and returns a single element or a default value.
- context: this ITransactionContext
- The active transaction context.
- sql: string
- The SQL query to execute.
- param: object?
- The parameters to pass to the query, or `null` if none.
- commandTimeout: int?
- The command execution timeout in seconds, or `null` to use the default.
- commandType: CommandType?
- The command type interpretation, or `null` for default.
- cancellationToken: CancellationToken
- A token that can be used to cancel the asynchronous operation.
Retorna: A task representing the asynchronous operation. The task result contains the single matching element, or the default value if none was found.