diff --git a/src/Dommel/Delete.cs b/src/Dommel/Delete.cs index 391ae2d..cedbf8d 100644 --- a/src/Dommel/Delete.cs +++ b/src/Dommel/Delete.cs @@ -2,6 +2,7 @@ using System.Data; using System.Linq; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; using Dapper; @@ -33,12 +34,13 @@ public static bool Delete(this IDbConnection connection, TEntity entity /// The connection to the database. This can either be open or closed. /// The entity to be deleted. /// Optional transaction for the command. + /// Optional cancellation token for the command. /// A value indicating whether the delete operation succeeded. - public static async Task DeleteAsync(this IDbConnection connection, TEntity entity, IDbTransaction? transaction = null) + public static async Task DeleteAsync(this IDbConnection connection, TEntity entity, IDbTransaction? transaction = null, CancellationToken cancellationToken = default) { var sql = BuildDeleteQuery(GetSqlBuilder(connection), typeof(TEntity)); LogQuery(sql); - return await connection.ExecuteAsync(sql, entity, transaction) > 0; + return await connection.ExecuteAsync(new CommandDefinition(sql, entity, transaction: transaction, cancellationToken: cancellationToken)) > 0; } internal static string BuildDeleteQuery(ISqlBuilder sqlBuilder, Type type) @@ -81,13 +83,14 @@ public static int DeleteMultiple(this IDbConnection connection, Express /// The type of the entity. /// The connection to the database. This can either be open or closed. /// A predicate to filter which entities are deleted. - /// Optional transaction for the command. + /// Optional transaction for the command. + /// Optional cancellation token for the command. /// The number of rows affected. - public static async Task DeleteMultipleAsync(this IDbConnection connection, Expression> predicate, IDbTransaction? transaction = null) + public static async Task DeleteMultipleAsync(this IDbConnection connection, Expression> predicate, IDbTransaction? transaction = null, CancellationToken cancellationToken = default) { var sql = BuildDeleteMultipleQuery(GetSqlBuilder(connection), predicate, out var parameters); LogQuery(sql); - return await connection.ExecuteAsync(sql, parameters, transaction); + return await connection.ExecuteAsync(new CommandDefinition(sql, parameters, transaction: transaction, cancellationToken: cancellationToken)); } private static string BuildDeleteMultipleQuery(ISqlBuilder sqlBuilder, Expression> predicate, out DynamicParameters parameters) @@ -125,12 +128,13 @@ public static int DeleteAll(this IDbConnection connection, IDbTransacti /// The type of the entity. /// The connection to the database. This can either be open or closed. /// Optional transaction for the command. + /// Optional cancellation token for the command. /// The number of rows affected. - public static async Task DeleteAllAsync(this IDbConnection connection, IDbTransaction? transaction = null) + public static async Task DeleteAllAsync(this IDbConnection connection, IDbTransaction? transaction = null, CancellationToken cancellationToken = default) { var sql = BuildDeleteAllQuery(GetSqlBuilder(connection), typeof(TEntity)); LogQuery(sql); - return await connection.ExecuteAsync(sql, transaction: transaction); + return await connection.ExecuteAsync(new CommandDefinition(sql, transaction: transaction, cancellationToken: cancellationToken)); } internal static string BuildDeleteAllQuery(ISqlBuilder sqlBuilder, Type type)