diff --git a/RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Operations/AverageAllTest.cs b/RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Operations/AverageAllTest.cs index f3dc1570f..6dd9009b8 100644 --- a/RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Operations/AverageAllTest.cs +++ b/RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Operations/AverageAllTest.cs @@ -276,7 +276,7 @@ public void TestSqlConnectionAverageAllTypedResultViaTableNameWithHints() #region AverageAllAsync(TableName) [TestMethod] - public void TestSqlConnectionAverageAllTableNameAsync() + public void TestSqlConnectionAverageAllAsyncViaTableName() { // Setup var tables = Helper.CreateIdentityTables(10); @@ -296,7 +296,7 @@ public void TestSqlConnectionAverageAllTableNameAsync() } [TestMethod] - public void TestSqlConnectionAverageAllTableNameAsyncWithHints() + public void TestSqlConnectionAverageAllAsyncViaTableNameWithHints() { // Setup var tables = Helper.CreateIdentityTables(10); @@ -317,7 +317,7 @@ public void TestSqlConnectionAverageAllTableNameAsyncWithHints() } [TestMethod] - public void TestSqlConnectionAverageAllTypedResultTableNameAsync() + public void TestSqlConnectionAverageAllTypedResultAsyncViaTableName() { // Setup var tables = Helper.CreateIdentityTables(10); @@ -337,7 +337,7 @@ public void TestSqlConnectionAverageAllTypedResultTableNameAsync() } [TestMethod] - public void TestSqlConnectionAverageAllTypedResultTableNameAsyncWithHints() + public void TestSqlConnectionAverageAllTypedResultAsyncViaTableNameWithHints() { // Setup var tables = Helper.CreateIdentityTables(10); diff --git a/RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Operations/CountAll.cs b/RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Operations/CountAll.cs index 8e8913b33..23e4aa1a2 100644 --- a/RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Operations/CountAll.cs +++ b/RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Operations/CountAll.cs @@ -108,7 +108,7 @@ public void TestSqlConnectionCountAllAsyncWithHints() #region CountAll(TableName) [TestMethod] - public void TestSqlConnectionCountViaAllTaleName() + public void TestSqlConnectionCountViaAllTableName() { // Setup var tables = Helper.CreateIdentityTables(10); @@ -127,7 +127,7 @@ public void TestSqlConnectionCountViaAllTaleName() } [TestMethod] - public void TestSqlConnectionCountAllViaTaleNameWithHints() + public void TestSqlConnectionCountAllViaTableNameWithHints() { // Setup var tables = Helper.CreateIdentityTables(10); @@ -151,7 +151,7 @@ public void TestSqlConnectionCountAllViaTaleNameWithHints() #region CountAllAsync(TableName) [TestMethod] - public void TestSqlConnectionCountAllTaleNameAsync() + public void TestSqlConnectionCountAllAsyncViaTableName() { // Setup var tables = Helper.CreateIdentityTables(10); @@ -170,7 +170,7 @@ public void TestSqlConnectionCountAllTaleNameAsync() } [TestMethod] - public void TestSqlConnectionCountAllTaleNameAsyncWithHints() + public void TestSqlConnectionCountAllAsyncViaTableNameWithHints() { // Setup var tables = Helper.CreateIdentityTables(10); diff --git a/RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Operations/CountTest.cs b/RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Operations/CountTest.cs index f1d21b1ef..5981825a8 100644 --- a/RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Operations/CountTest.cs +++ b/RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Operations/CountTest.cs @@ -401,7 +401,7 @@ public void TestSqlConnectionCountViaTableNameViaQueryGroup() #region CountAsync(TableName) [TestMethod] - public void TestSqlConnectionCountViaTableNameAsyncWithoutCondition() + public void TestSqlConnectionCountViaAsyncViaTableNameWithoutCondition() { // Setup var tables = Helper.CreateIdentityTables(10); @@ -421,7 +421,7 @@ public void TestSqlConnectionCountViaTableNameAsyncWithoutCondition() } [TestMethod] - public void TestSqlConnectionCountViaTableNameAsyncViaDynamic() + public void TestSqlConnectionCountViaAsyncViaTableNameViaDynamic() { // Setup var tables = Helper.CreateIdentityTables(10); @@ -440,7 +440,7 @@ public void TestSqlConnectionCountViaTableNameAsyncViaDynamic() } [TestMethod] - public void TestSqlConnectionCountViaTableNameAsyncViaQueryField() + public void TestSqlConnectionCountViaAsyncViaTableNameViaQueryField() { // Setup var tables = Helper.CreateIdentityTables(10); @@ -461,7 +461,7 @@ public void TestSqlConnectionCountViaTableNameAsyncViaQueryField() } [TestMethod] - public void TestSqlConnectionCountViaTableNameAsyncViaQueryFields() + public void TestSqlConnectionCountViaAsyncViaTableNameViaQueryFields() { // Setup var tables = Helper.CreateIdentityTables(10); @@ -486,7 +486,7 @@ public void TestSqlConnectionCountViaTableNameAsyncViaQueryFields() } [TestMethod] - public void TestSqlConnectionCountViaTableNameAsyncViaQueryGroup() + public void TestSqlConnectionCountViaAsyncViaTableNameViaQueryGroup() { // Setup var tables = Helper.CreateIdentityTables(10); diff --git a/RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Operations/ExistsTest.cs b/RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Operations/ExistsTest.cs index e2b3f0468..da4a7700b 100644 --- a/RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Operations/ExistsTest.cs +++ b/RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Operations/ExistsTest.cs @@ -401,7 +401,7 @@ public void TestSqlConnectionExistsViaTableNameViaQueryGroup() #region ExistsAsync(TableName) [TestMethod] - public void TestSqlConnectionExistsViaTableNameAsyncWithoutCondition() + public void TestSqlConnectionExistsViaAsyncViaTableNameWithoutCondition() { // Setup var tables = Helper.CreateIdentityTables(10); @@ -421,7 +421,7 @@ public void TestSqlConnectionExistsViaTableNameAsyncWithoutCondition() } [TestMethod] - public void TestSqlConnectionExistsViaTableNameAsyncViaDynamic() + public void TestSqlConnectionExistsViaAsyncViaTableNameViaDynamic() { // Setup var tables = Helper.CreateIdentityTables(10); @@ -440,7 +440,7 @@ public void TestSqlConnectionExistsViaTableNameAsyncViaDynamic() } [TestMethod] - public void TestSqlConnectionExistsViaTableNameAsyncViaQueryField() + public void TestSqlConnectionExistsViaAsyncViaTableNameViaQueryField() { // Setup var tables = Helper.CreateIdentityTables(10); @@ -461,7 +461,7 @@ public void TestSqlConnectionExistsViaTableNameAsyncViaQueryField() } [TestMethod] - public void TestSqlConnectionExistsViaTableNameAsyncViaQueryFields() + public void TestSqlConnectionExistsViaAsyncViaTableNameViaQueryFields() { // Setup var tables = Helper.CreateIdentityTables(10); @@ -486,7 +486,7 @@ public void TestSqlConnectionExistsViaTableNameAsyncViaQueryFields() } [TestMethod] - public void TestSqlConnectionExistsViaTableNameAsyncViaQueryGroup() + public void TestSqlConnectionExistsViaAsyncViaTableNameViaQueryGroup() { // Setup var tables = Helper.CreateIdentityTables(10); diff --git a/RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Operations/MaxAllTest.cs b/RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Operations/MaxAllTest.cs index 7add71b99..58bf6e120 100644 --- a/RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Operations/MaxAllTest.cs +++ b/RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Operations/MaxAllTest.cs @@ -276,7 +276,7 @@ public void TestSqlConnectionMaxAllTypedResultViaTableNameWithHints() #region MaxAllAsync(TableName) [TestMethod] - public void TestSqlConnectionMaxAllTableNameAsync() + public void TestSqlConnectionMaxAllAsyncViaTableName() { // Setup var tables = Helper.CreateIdentityTables(10); @@ -296,7 +296,7 @@ public void TestSqlConnectionMaxAllTableNameAsync() } [TestMethod] - public void TestSqlConnectionMaxAllTableNameAsyncWithHints() + public void TestSqlConnectionMaxAllAsyncViaTableNameWithHints() { // Setup var tables = Helper.CreateIdentityTables(10); @@ -317,7 +317,7 @@ public void TestSqlConnectionMaxAllTableNameAsyncWithHints() } [TestMethod] - public void TestSqlConnectionMaxAllTypedResultTableNameAsync() + public void TestSqlConnectionMaxAllTypedResultAsyncViaTableName() { // Setup var tables = Helper.CreateIdentityTables(10); @@ -337,7 +337,7 @@ public void TestSqlConnectionMaxAllTypedResultTableNameAsync() } [TestMethod] - public void TestSqlConnectionMaxAllTypedResultTableNameAsyncWithHints() + public void TestSqlConnectionMaxAllTypedResultAsyncViaTableNameWithHints() { // Setup var tables = Helper.CreateIdentityTables(10); diff --git a/RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Operations/MinAllTest.cs b/RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Operations/MinAllTest.cs index ff25e1f44..96d7c1b02 100644 --- a/RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Operations/MinAllTest.cs +++ b/RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Operations/MinAllTest.cs @@ -276,7 +276,7 @@ public void TestSqlConnectionMinAllTypedResultViaTableNameWithHints() #region MinAllAsync(TableName) [TestMethod] - public void TestSqlConnectionMinAllTableNameAsync() + public void TestSqlConnectionMinAllAsyncViaTableName() { // Setup var tables = Helper.CreateIdentityTables(10); @@ -296,7 +296,7 @@ public void TestSqlConnectionMinAllTableNameAsync() } [TestMethod] - public void TestSqlConnectionMinAllTableNameAsyncWithHints() + public void TestSqlConnectionMinAllAsyncViaTableNameWithHints() { // Setup var tables = Helper.CreateIdentityTables(10); @@ -317,7 +317,7 @@ public void TestSqlConnectionMinAllTableNameAsyncWithHints() } [TestMethod] - public void TestSqlConnectionMinAllTypedResultTableNameAsync() + public void TestSqlConnectionMinAllTypedResultAsyncViaTableName() { // Setup var tables = Helper.CreateIdentityTables(10); @@ -337,7 +337,7 @@ public void TestSqlConnectionMinAllTypedResultTableNameAsync() } [TestMethod] - public void TestSqlConnectionMinAllTypedResultTableNameAsyncWithHints() + public void TestSqlConnectionMinAllTypedResultAsyncViaTableNameWithHints() { // Setup var tables = Helper.CreateIdentityTables(10); diff --git a/RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Operations/SumAllTest.cs b/RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Operations/SumAllTest.cs index 31c2007b9..7677cebf9 100644 --- a/RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Operations/SumAllTest.cs +++ b/RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Operations/SumAllTest.cs @@ -276,7 +276,7 @@ public void TestSqlConnectionSumAllTypedResultViaTableNameWithHints() #region SumAllAsync(TableName) [TestMethod] - public void TestSqlConnectionSumAllTableNameAsync() + public void TestSqlConnectionSumAllAsyncViaTableName() { // Setup var tables = Helper.CreateIdentityTables(10); @@ -296,7 +296,7 @@ public void TestSqlConnectionSumAllTableNameAsync() } [TestMethod] - public void TestSqlConnectionSumAllTableNameAsyncWithHints() + public void TestSqlConnectionSumAllAsyncViaTableNameWithHints() { // Setup var tables = Helper.CreateIdentityTables(10); @@ -317,7 +317,7 @@ public void TestSqlConnectionSumAllTableNameAsyncWithHints() } [TestMethod] - public void TestSqlConnectionSumAllTypedResultTableNameAsync() + public void TestSqlConnectionSumAllTypedResultAsyncViaTableName() { // Setup var tables = Helper.CreateIdentityTables(10); @@ -337,7 +337,7 @@ public void TestSqlConnectionSumAllTypedResultTableNameAsync() } [TestMethod] - public void TestSqlConnectionSumAllTypedResultTableNameAsyncWithHints() + public void TestSqlConnectionSumAllTypedResultAsyncViaTableNameWithHints() { // Setup var tables = Helper.CreateIdentityTables(10); diff --git a/RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Operations/UpdateTest.cs b/RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Operations/UpdateTest.cs index 0b0ed7357..031426141 100644 --- a/RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Operations/UpdateTest.cs +++ b/RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Operations/UpdateTest.cs @@ -1364,7 +1364,7 @@ public void TestSqlConnectionUpdateViaTableNameWithFields() } [TestMethod] - public void TestSqlConnectionUpdateViaDynamicTableNameAsyncViaPrimaryKey() + public void TestSqlConnectionUpdateViaDynamicAsyncViaTableNameViaPrimaryKey() { // Setup var table = Helper.CreateNonIdentityTable(); @@ -1817,7 +1817,7 @@ public void TestSqlConnectionUpdateAsyncViaTableNameWithFields() } [TestMethod] - public void TestSqlConnectionUpdateAsyncViaDynamicTableNameAsyncViaPrimaryKey() + public void TestSqlConnectionUpdateAsyncViaDynamicAsyncViaTableNameViaPrimaryKey() { // Setup var table = Helper.CreateNonIdentityTable(); @@ -1847,7 +1847,7 @@ public void TestSqlConnectionUpdateAsyncViaDynamicTableNameAsyncViaPrimaryKey() } [TestMethod] - public void TestSqlConnectionUpdateViaTableNameAsyncViaPrimaryKey() + public void TestSqlConnectionUpdateViaAsyncViaTableNameViaPrimaryKey() { // Setup var table = Helper.CreateNonIdentityTable(); @@ -1873,7 +1873,7 @@ public void TestSqlConnectionUpdateViaTableNameAsyncViaPrimaryKey() } [TestMethod] - public void TestSqlConnectionUpdateViaTableNameAsyncViaDynamic() + public void TestSqlConnectionUpdateViaAsyncViaTableNameViaDynamic() { // Setup var table = Helper.CreateIdentityTable(); @@ -1905,7 +1905,7 @@ public void TestSqlConnectionUpdateViaTableNameAsyncViaDynamic() } [TestMethod] - public void TestSqlConnectionUpdateViaTableNameAsyncViaQueryField() + public void TestSqlConnectionUpdateViaAsyncViaTableNameViaQueryField() { // Setup var table = Helper.CreateIdentityTable(); @@ -1940,7 +1940,7 @@ public void TestSqlConnectionUpdateViaTableNameAsyncViaQueryField() } [TestMethod] - public void TestSqlConnectionUpdateViaTableNameAsyncViaQueryFields() + public void TestSqlConnectionUpdateViaAsyncViaTableNameViaQueryFields() { // Setup var table = Helper.CreateIdentityTable(); @@ -1980,7 +1980,7 @@ public void TestSqlConnectionUpdateViaTableNameAsyncViaQueryFields() } [TestMethod] - public void TestSqlConnectionUpdateViaTableNameAsyncViaQueryGroup() + public void TestSqlConnectionUpdateViaAsyncViaTableNameViaQueryGroup() { // Setup var table = Helper.CreateIdentityTable(); diff --git a/RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Types/SqlConnectionBytesTest.cs b/RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Types/SqlConnectionBytesTest.cs index 026b4f101..e51841d3a 100644 --- a/RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Types/SqlConnectionBytesTest.cs +++ b/RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Types/SqlConnectionBytesTest.cs @@ -24,7 +24,7 @@ public void Cleanup() Database.Cleanup(); } - #region + #region Operation [TestMethod] public void TestSqlConnectionBytesCrud() @@ -284,7 +284,7 @@ public void TestSqlConnectionBytesMappedNullCrudAsync() #endregion - #region (TableName) + #region Operation(TableName) [TestMethod] public void TestSqlConnectionBytesCrudViaTableName() @@ -349,7 +349,7 @@ public void TestSqlConnectionBytesNullCrudViaTableName() } [TestMethod] - public void TestSqlConnectionBytesCrudViaTableNameAsync() + public void TestSqlConnectionBytesCrudViaAsyncViaTableName() { // Setup var text = "RepoDb"; // Helper.GetAssemblyDescription(); @@ -383,7 +383,7 @@ public void TestSqlConnectionBytesCrudViaTableNameAsync() } [TestMethod] - public void TestSqlConnectionBytesNullCrudViaTableNameAsync() + public void TestSqlConnectionBytesNullCrudViaAsyncViaTableName() { // Setup var entity = new diff --git a/RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Types/SqlConnectionDatesTest.cs b/RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Types/SqlConnectionDatesTest.cs index 003400896..9326ae703 100644 --- a/RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Types/SqlConnectionDatesTest.cs +++ b/RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Types/SqlConnectionDatesTest.cs @@ -386,7 +386,7 @@ public void TestSqlConnectionDatesNullCrudViaTableName() } [TestMethod] - public void TestSqlConnectionDatesCrudViaTableNameAsync() + public void TestSqlConnectionDatesCrudViaAsyncViaTableName() { // Setup var dateTime = new DateTime(1970, 1, 1, 12, 50, 30, DateTimeKind.Utc); @@ -424,7 +424,7 @@ public void TestSqlConnectionDatesCrudViaTableNameAsync() } [TestMethod] - public void TestSqlConnectionDatesNullCrudViaTableNameAsync() + public void TestSqlConnectionDatesNullCrudViaAsyncViaTableName() { // Setup var entity = new diff --git a/RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Types/SqlConnectionNumbersTest.cs b/RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Types/SqlConnectionNumbersTest.cs index 472eb384a..e5c5bc4be 100644 --- a/RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Types/SqlConnectionNumbersTest.cs +++ b/RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Types/SqlConnectionNumbersTest.cs @@ -458,7 +458,7 @@ public void TestSqlConnectionNumbersNullViaTableNameCrud() } [TestMethod] - public void TestSqlConnectionNumbersCrudViaTableNameAsync() + public void TestSqlConnectionNumbersCrudViaAsyncViaTableName() { // Setup var entity = new @@ -502,7 +502,7 @@ public void TestSqlConnectionNumbersCrudViaTableNameAsync() } [TestMethod] - public void TestSqlConnectionNumbersNullCrudViaTableNameAsync() + public void TestSqlConnectionNumbersNullCrudViaAsyncViaTableName() { // Setup var entity = new diff --git a/RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Types/SqlConnectionOthersTest.cs b/RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Types/SqlConnectionOthersTest.cs index 7a049b8cc..0e459863e 100644 --- a/RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Types/SqlConnectionOthersTest.cs +++ b/RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Types/SqlConnectionOthersTest.cs @@ -338,7 +338,7 @@ public void TestSqlConnectionOthersNullCrudViaTableName() } [TestMethod] - public void TestSqlConnectionOthersCrudViaTableNameAsync() + public void TestSqlConnectionOthersCrudViaAsyncViaTableName() { // Setup var entity = new @@ -370,7 +370,7 @@ public void TestSqlConnectionOthersCrudViaTableNameAsync() } [TestMethod] - public void TestSqlConnectionOthersNullCrudViaTableNameAsync() + public void TestSqlConnectionOthersNullCrudViaAsyncViaTableName() { // Setup var entity = new diff --git a/RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Types/SqlConnectionSpatialsTest.cs b/RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Types/SqlConnectionSpatialsTest.cs index 2e398378d..d8e02cf7d 100644 --- a/RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Types/SqlConnectionSpatialsTest.cs +++ b/RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Types/SqlConnectionSpatialsTest.cs @@ -298,7 +298,7 @@ public void TestSqlConnectionSpatialsNullCrudViaTableName() } [TestMethod] - public void TestSqlConnectionSpatialsCrudViaTableNameAsync() + public void TestSqlConnectionSpatialsCrudViaAsyncViaTableName() { // Setup var entity = new @@ -326,7 +326,7 @@ public void TestSqlConnectionSpatialsCrudViaTableNameAsync() } [TestMethod] - public void TestSqlConnectionSpatialsNullCrudViaTableNameAsync() + public void TestSqlConnectionSpatialsNullCrudViaAsyncViaTableName() { // Setup var entity = new diff --git a/RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Types/SqlConnectionStringsTest.cs b/RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Types/SqlConnectionStringsTest.cs index 2bf3506a1..30977f0de 100644 --- a/RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Types/SqlConnectionStringsTest.cs +++ b/RepoDb.Core/RepoDb.Tests/RepoDb.IntegrationTests/Types/SqlConnectionStringsTest.cs @@ -383,7 +383,7 @@ public void TestSqlConnectionStringsNullCrudViaTableName() } [TestMethod] - public void TestSqlConnectionStringsCrudViaTableNameAsync() + public void TestSqlConnectionStringsCrudViaAsyncViaTableName() { // Setup var text = Helper.GetUnicodeString(); @@ -420,7 +420,7 @@ public void TestSqlConnectionStringsCrudViaTableNameAsync() } [TestMethod] - public void TestSqlConnectionStringsNullCrudViaTableNameAsync() + public void TestSqlConnectionStringsNullCrudViaAsyncViaTableName() { // Setup var entity = new diff --git a/RepoDb.Core/RepoDb.Tests/RepoDb.UnitTests/CustomObjects/CustomDbHelper.cs b/RepoDb.Core/RepoDb.Tests/RepoDb.UnitTests/CustomObjects/CustomDbHelper.cs index 5ca280b5c..32858c851 100644 --- a/RepoDb.Core/RepoDb.Tests/RepoDb.UnitTests/CustomObjects/CustomDbHelper.cs +++ b/RepoDb.Core/RepoDb.Tests/RepoDb.UnitTests/CustomObjects/CustomDbHelper.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Data; +using System.Threading; using System.Threading.Tasks; namespace RepoDb.UnitTests.CustomObjects @@ -23,7 +24,8 @@ public IEnumerable GetFields(IDbConnection connection, public Task> GetFieldsAsync(IDbConnection connection, string tableName, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return Task.FromResult>(new[] { @@ -39,7 +41,8 @@ public object GetScopeIdentity(IDbConnection connection, } public Task GetScopeIdentityAsync(IDbConnection connection, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return Task.FromResult((object)0); } diff --git a/RepoDb.Core/RepoDb/BaseRepository.cs b/RepoDb.Core/RepoDb/BaseRepository.cs index 89612e22c..4f82f7571 100644 --- a/RepoDb.Core/RepoDb/BaseRepository.cs +++ b/RepoDb.Core/RepoDb/BaseRepository.cs @@ -6,6 +6,7 @@ using RepoDb.Enumerations; using System; using System.Dynamic; +using System.Threading; namespace RepoDb { @@ -345,6 +346,7 @@ public IEnumerable ExecuteQuery(string commandText, /// /// The expiration in minutes of the cache item. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// /// An enumerable list of data entity objects containing the converted results of the underlying object. /// @@ -353,14 +355,16 @@ public Task> ExecuteQueryAsync(string commandText, CommandType? commandType = null, string cacheKey = null, int? cacheItemExpiration = Constant.DefaultCacheItemExpirationInMinutes, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.ExecuteQueryAsync(commandText: commandText, param: param, commandType: commandType, cacheKey: cacheKey, cacheItemExpiration: cacheItemExpiration, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } #endregion @@ -405,16 +409,19 @@ public int ExecuteNonQuery(string commandText, /// /// The command type to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public Task ExecuteNonQueryAsync(string commandText, object param = null, CommandType? commandType = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.ExecuteNonQueryAsync(commandText: commandText, param: param, commandType: commandType, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } #endregion @@ -459,16 +466,19 @@ public object ExecuteScalar(string commandText, /// /// The command type to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An object that holds the first occurence value (first column of first row) of the execution. public Task ExecuteScalarAsync(string commandText, object param = null, CommandType? commandType = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.ExecuteScalarAsync(commandText: commandText, param: param, commandType: commandType, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } #endregion @@ -515,16 +525,19 @@ public TResult ExecuteScalar(string commandText, /// /// The command type to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// A first occurence value (first column of first row) of the execution. public Task ExecuteScalarAsync(string commandText, object param = null, CommandType? commandType = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.ExecuteScalarAsync(commandText: commandText, param: param, commandType: commandType, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } #endregion diff --git a/RepoDb.Core/RepoDb/Cachers/DbFieldCache.cs b/RepoDb.Core/RepoDb/Cachers/DbFieldCache.cs index 74becb5c9..7fcdaef0a 100644 --- a/RepoDb.Core/RepoDb/Cachers/DbFieldCache.cs +++ b/RepoDb.Core/RepoDb/Cachers/DbFieldCache.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Data; using System.Linq; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -130,11 +131,13 @@ internal static IEnumerable GetInternal(TDbConnection co /// The connection object to be used. /// The name of the target table. /// The transaction object that is currently in used. + /// The object to be used during the asynchronous operation. /// The cached field definitions of the entity. public static Task> GetAsync(IDbConnection connection, string tableName, - IDbTransaction transaction) => - GetAsync(connection, tableName, transaction, true); + IDbTransaction transaction, + CancellationToken cancellationToken = default) => + GetAsync(connection, tableName, transaction, true, cancellationToken); /// /// Gets the cached list of objects of the table based on the data entity mapped name in an asynchronous way. @@ -143,12 +146,14 @@ public static Task> GetAsync(IDbConnection connection, /// The name of the target table. /// The transaction object that is currently in used. /// Enables the validation after retrieving the database fields. + /// The object to be used during the asynchronous operation. /// The cached field definitions of the entity. public static Task> GetAsync(IDbConnection connection, string tableName, IDbTransaction transaction, - bool enableValidation) => - GetAsyncInternal(connection, tableName, transaction, enableValidation); + bool enableValidation, + CancellationToken cancellationToken = default) => + GetAsyncInternal(connection, tableName, transaction, enableValidation, cancellationToken); /// /// Gets the cached field definitions of the entity in an asychronous way. @@ -158,11 +163,13 @@ public static Task> GetAsync(IDbConnection connection, /// The name of the target table. /// The transaction object that is currently in used. /// Enables the validation after retrieving the database fields. + /// The object to be used during the asynchronous operation. /// The cached field definitions of the entity. internal static async Task> GetAsyncInternal(TDbConnection connection, string tableName, IDbTransaction transaction, - bool enableValidation) + bool enableValidation, + CancellationToken cancellationToken = default) where TDbConnection : IDbConnection { var type = connection.GetType(); @@ -186,7 +193,7 @@ internal static async Task> GetAsyncInternal { // Get from DB var dbHelper = DbHelperMapper.Get(type); - result = await dbHelper?.GetFieldsAsync(connection, tableName, transaction); + result = await dbHelper?.GetFieldsAsync(connection, tableName, transaction, cancellationToken); // Validate if (enableValidation) diff --git a/RepoDb.Core/RepoDb/Contexts/Providers/InsertAllExecutionContextProvider.cs b/RepoDb.Core/RepoDb/Contexts/Providers/InsertAllExecutionContextProvider.cs index 45f6dd61d..3f94b4883 100644 --- a/RepoDb.Core/RepoDb/Contexts/Providers/InsertAllExecutionContextProvider.cs +++ b/RepoDb.Core/RepoDb/Contexts/Providers/InsertAllExecutionContextProvider.cs @@ -8,6 +8,7 @@ using System.Data; using System.Data.Common; using System.Linq; +using System.Threading; using System.Threading.Tasks; namespace RepoDb.Contexts.Providers @@ -101,6 +102,7 @@ public static InsertAllExecutionContext Create(IDbConnection c /// /// /// + /// /// public static async Task> CreateAsync(IDbConnection connection, string tableName, @@ -108,7 +110,8 @@ public static async Task> CreateAsync fields, string hints = null, IDbTransaction transaction = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { var key = GetKey(tableName, fields, batchSize, hints); @@ -121,7 +124,7 @@ public static async Task> CreateAsync(connection, tableName, dbFields, diff --git a/RepoDb.Core/RepoDb/Contexts/Providers/InsertExecutionContextProvider.cs b/RepoDb.Core/RepoDb/Contexts/Providers/InsertExecutionContextProvider.cs index 9c70b95df..e10b16bae 100644 --- a/RepoDb.Core/RepoDb/Contexts/Providers/InsertExecutionContextProvider.cs +++ b/RepoDb.Core/RepoDb/Contexts/Providers/InsertExecutionContextProvider.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.Data; using System.Linq; +using System.Threading; using System.Threading.Tasks; namespace RepoDb.Contexts.Providers @@ -92,13 +93,15 @@ public static InsertExecutionContext Create(IDbConnection conn /// /// /// + /// /// public static async Task> CreateAsync(IDbConnection connection, string tableName, IEnumerable fields, string hints = null, IDbTransaction transaction = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { var key = GetKey(tableName, fields, hints); @@ -111,7 +114,7 @@ public static async Task> CreateAsync(I } // Create - var dbFields = await DbFieldCache.GetAsync(connection, tableName, transaction); + var dbFields = await DbFieldCache.GetAsync(connection, tableName, transaction, cancellationToken); context = CreateInternal(connection, dbFields, tableName, diff --git a/RepoDb.Core/RepoDb/Contexts/Providers/MergeAllExecutionContextProvider.cs b/RepoDb.Core/RepoDb/Contexts/Providers/MergeAllExecutionContextProvider.cs index 1a57ebe87..a8b72f61c 100644 --- a/RepoDb.Core/RepoDb/Contexts/Providers/MergeAllExecutionContextProvider.cs +++ b/RepoDb.Core/RepoDb/Contexts/Providers/MergeAllExecutionContextProvider.cs @@ -8,6 +8,7 @@ using System.Data; using System.Data.Common; using System.Linq; +using System.Threading; using System.Threading.Tasks; namespace RepoDb.Contexts.Providers @@ -113,6 +114,7 @@ public static MergeAllExecutionContext Create(IDbConnection co /// /// /// + /// /// public static async Task> CreateAsync(IDbConnection connection, IEnumerable entities, @@ -122,7 +124,8 @@ public static async Task> CreateAsync IEnumerable fields, string hints = null, IDbTransaction transaction = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { var key = GetKey(tableName, qualifiers, fields, batchSize, hints); @@ -135,7 +138,7 @@ public static async Task> CreateAsync } // Create - var dbFields = await DbFieldCache.GetAsync(connection, tableName, transaction); + var dbFields = await DbFieldCache.GetAsync(connection, tableName, transaction, cancellationToken); context = CreateInternal(connection, entities, dbFields, diff --git a/RepoDb.Core/RepoDb/Contexts/Providers/MergeExecutionContextProvider.cs b/RepoDb.Core/RepoDb/Contexts/Providers/MergeExecutionContextProvider.cs index de869e509..c90c24261 100644 --- a/RepoDb.Core/RepoDb/Contexts/Providers/MergeExecutionContextProvider.cs +++ b/RepoDb.Core/RepoDb/Contexts/Providers/MergeExecutionContextProvider.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.Data; using System.Linq; +using System.Threading; using System.Threading.Tasks; namespace RepoDb.Contexts.Providers @@ -100,6 +101,7 @@ public static MergeExecutionContext Create(IDbConnection conne /// /// /// + /// /// public static async Task> CreateAsync(IDbConnection connection, string tableName, @@ -107,7 +109,8 @@ public static async Task> CreateAsync(ID IEnumerable fields, string hints = null, IDbTransaction transaction = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { var key = GetKey(tableName, qualifiers, fields, hints); @@ -120,7 +123,7 @@ public static async Task> CreateAsync(ID } // Create - var dbFields = await DbFieldCache.GetAsync(connection, tableName, transaction); + var dbFields = await DbFieldCache.GetAsync(connection, tableName, transaction, cancellationToken); context = CreateInternal(connection, dbFields, tableName, diff --git a/RepoDb.Core/RepoDb/Contexts/Providers/UpdateAllExecutionContextProvider.cs b/RepoDb.Core/RepoDb/Contexts/Providers/UpdateAllExecutionContextProvider.cs index 82a63383b..136544d96 100644 --- a/RepoDb.Core/RepoDb/Contexts/Providers/UpdateAllExecutionContextProvider.cs +++ b/RepoDb.Core/RepoDb/Contexts/Providers/UpdateAllExecutionContextProvider.cs @@ -8,6 +8,7 @@ using System.Data; using System.Data.Common; using System.Linq; +using System.Threading; using System.Threading.Tasks; namespace RepoDb.Contexts.Providers @@ -113,6 +114,7 @@ public static UpdateAllExecutionContext Create(IDbConnection c /// /// /// + /// /// public static async Task> CreateAsync(IDbConnection connection, string tableName, @@ -122,7 +124,8 @@ public static async Task> CreateAsync fields, string hints = null, IDbTransaction transaction = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { var key = GetKey(tableName, qualifiers, fields, batchSize, hints); @@ -135,7 +138,7 @@ public static async Task> CreateAsync(connection, tableName, entities, diff --git a/RepoDb.Core/RepoDb/Contexts/Providers/UpdateExecutionContextProvider.cs b/RepoDb.Core/RepoDb/Contexts/Providers/UpdateExecutionContextProvider.cs index 597fad94a..4ea022fea 100644 --- a/RepoDb.Core/RepoDb/Contexts/Providers/UpdateExecutionContextProvider.cs +++ b/RepoDb.Core/RepoDb/Contexts/Providers/UpdateExecutionContextProvider.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.Data; using System.Linq; +using System.Threading; using System.Threading.Tasks; namespace RepoDb.Contexts.Providers @@ -100,6 +101,7 @@ public static UpdateExecutionContext Create(IDbConnection conn /// /// /// + /// /// public static async Task> CreateAsync(IDbConnection connection, string tableName, @@ -107,7 +109,8 @@ public static async Task> CreateAsync(I IEnumerable fields, string hints = null, IDbTransaction transaction = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { var key = GetKey(tableName, fields, hints, where); @@ -120,7 +123,7 @@ public static async Task> CreateAsync(I } // Create - var dbFields = await DbFieldCache.GetAsync(connection, tableName, transaction); + var dbFields = await DbFieldCache.GetAsync(connection, tableName, transaction, cancellationToken); context = CreateInternal(connection, tableName, where, diff --git a/RepoDb.Core/RepoDb/DataEntityDataReader.cs b/RepoDb.Core/RepoDb/DataEntityDataReader.cs index 6d4b0fb99..ea1df6350 100644 --- a/RepoDb.Core/RepoDb/DataEntityDataReader.cs +++ b/RepoDb.Core/RepoDb/DataEntityDataReader.cs @@ -7,6 +7,7 @@ using RepoDb.Extensions; using RepoDb.Interfaces; using System.Threading.Tasks; +using System.Threading; namespace RepoDb { @@ -100,7 +101,8 @@ public void Initialize() /// /// Initializes the current instance of object. /// - public async Task InitializeAsync() + /// The object to be used during the asynchronous operation. + public async Task InitializeAsync(CancellationToken cancellationToken = default) { if (IsInitialized) { @@ -109,7 +111,7 @@ public async Task InitializeAsync() var dbFields = (IEnumerable)null; if (Connection != null) { - dbFields = await DbFieldCache.GetAsync(Connection, ClassMappedNameCache.Get(), Transaction); + dbFields = await DbFieldCache.GetAsync(Connection, ClassMappedNameCache.Get(), Transaction, cancellationToken); } InitializeInternal(dbFields); } diff --git a/RepoDb.Core/RepoDb/DbRepository.cs b/RepoDb.Core/RepoDb/DbRepository.cs index f58b3e5e8..4d3f5adfa 100644 --- a/RepoDb.Core/RepoDb/DbRepository.cs +++ b/RepoDb.Core/RepoDb/DbRepository.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using RepoDb.Enumerations; using System.Dynamic; +using System.Threading; namespace RepoDb { @@ -412,6 +413,7 @@ public IEnumerable ExecuteQuery(string commandText, /// /// The expiration in minutes of the cache item. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// /// An enumerable list of dynamic objects containing the converted results of the underlying object. /// @@ -420,7 +422,8 @@ public async Task> ExecuteQueryAsync(string commandText, CommandType? commandType = null, string cacheKey = null, int? cacheItemExpiration = Constant.DefaultCacheItemExpirationInMinutes, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -435,7 +438,8 @@ public async Task> ExecuteQueryAsync(string commandText, cacheItemExpiration: cacheItemExpiration, commandTimeout: CommandTimeout, transaction: transaction, - cache: Cache); + cache: Cache, + cancellationToken: cancellationToken); } catch { @@ -527,6 +531,7 @@ public IEnumerable ExecuteQuery(string commandText, /// /// The expiration in minutes of the cache item. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// /// An enumerable list of data entity objects containing the converted results of the underlying object. /// @@ -535,7 +540,8 @@ public async Task> ExecuteQueryAsync(string comman CommandType? commandType = null, string cacheKey = null, int? cacheItemExpiration = Constant.DefaultCacheItemExpirationInMinutes, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -551,7 +557,8 @@ public async Task> ExecuteQueryAsync(string comman cacheItemExpiration: cacheItemExpiration, commandTimeout: CommandTimeout, transaction: transaction, - cache: Cache); + cache: Cache, + cancellationToken: cancellationToken); } catch { @@ -625,11 +632,13 @@ public int ExecuteNonQuery(string commandText, /// /// The command type to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public async Task ExecuteNonQueryAsync(string commandText, object param = null, CommandType? commandType = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -641,7 +650,8 @@ public async Task ExecuteNonQueryAsync(string commandText, param: param, commandType: commandType, commandTimeout: CommandTimeout, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } catch { @@ -715,11 +725,13 @@ public object ExecuteScalar(string commandText, /// /// The command type to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An object that holds the first occurence value (first column of first row) of the execution. public async Task ExecuteScalarAsync(string commandText, object param = null, CommandType? commandType = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -731,7 +743,8 @@ public async Task ExecuteScalarAsync(string commandText, param: param, commandType: commandType, commandTimeout: CommandTimeout, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } catch { @@ -807,11 +820,13 @@ public TResult ExecuteScalar(string commandText, /// /// The command type to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// A first occurence value (first column of first row) of the execution. public async Task ExecuteScalarAsync(string commandText, object param = null, CommandType? commandType = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -823,7 +838,8 @@ public async Task ExecuteScalarAsync(string commandText, param: param, commandType: commandType, commandTimeout: CommandTimeout, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } catch { diff --git a/RepoDb.Core/RepoDb/Extensions/DbConnectionExtension.cs b/RepoDb.Core/RepoDb/Extensions/DbConnectionExtension.cs index 31c1e04c9..60265afa7 100644 --- a/RepoDb.Core/RepoDb/Extensions/DbConnectionExtension.cs +++ b/RepoDb.Core/RepoDb/Extensions/DbConnectionExtension.cs @@ -10,6 +10,7 @@ using System.Dynamic; using System.Linq; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -85,12 +86,14 @@ public static IDbConnection EnsureOpen(this IDbConnection connection) /// Ensures the connection object is open in an asynchronous way. /// /// The connection to be opened. + /// The object to be used during the asynchronous operation. /// The instance of the current connection object. - public static async Task EnsureOpenAsync(this IDbConnection connection) + public static async Task EnsureOpenAsync(this IDbConnection connection, + CancellationToken cancellationToken = default) { if (connection.State != ConnectionState.Open) { - await ((DbConnection)connection).OpenAsync(); + await ((DbConnection)connection).OpenAsync(cancellationToken); } return connection; } @@ -235,6 +238,7 @@ internal static IEnumerable ExecuteQueryInternal(this IDbConnection con /// The command timeout in seconds to be used. /// The transaction to be used. /// The cache object to be used. + /// The object to be used during the asynchronous operation. /// /// An enumerable list of dynamic objects containing the converted results of the underlying object. /// @@ -246,7 +250,8 @@ public static Task> ExecuteQueryAsync(this IDbConnection co int? cacheItemExpiration = Constant.DefaultCacheItemExpirationInMinutes, int? commandTimeout = null, IDbTransaction transaction = null, - ICache cache = null) + ICache cache = null, + CancellationToken cancellationToken = default) { return ExecuteQueryAsyncInternal(connection: connection, commandText: commandText, @@ -257,6 +262,7 @@ public static Task> ExecuteQueryAsync(this IDbConnection co commandTimeout: commandTimeout, transaction: transaction, cache: cache, + cancellationToken: cancellationToken, tableName: null, skipCommandArrayParametersCheck: false); } @@ -273,6 +279,7 @@ public static Task> ExecuteQueryAsync(this IDbConnection co /// /// /// + /// /// /// /// @@ -285,6 +292,7 @@ internal static async Task> ExecuteQueryAsyncInternal(this int? commandTimeout = null, IDbTransaction transaction = null, ICache cache = null, + CancellationToken cancellationToken = default, string tableName = null, bool skipCommandArrayParametersCheck = true) { @@ -300,7 +308,7 @@ internal static async Task> ExecuteQueryAsyncInternal(this // DB Fields var dbFields = !string.IsNullOrWhiteSpace(tableName) ? - await DbFieldCache.GetAsync(connection, tableName, transaction, false) : null; + await DbFieldCache.GetAsync(connection, tableName, transaction, false, cancellationToken) : null; // Execute the actual method using (var command = await CreateDbCommandForExecutionAsync(connection: connection, @@ -309,11 +317,12 @@ internal static async Task> ExecuteQueryAsyncInternal(this commandType: commandType, commandTimeout: commandTimeout, transaction: transaction, + cancellationToken: cancellationToken, entityType: null, dbFields: dbFields, skipCommandArrayParametersCheck: skipCommandArrayParametersCheck)) { - using (var reader = await command.ExecuteReaderAsync()) + using (var reader = await command.ExecuteReaderAsync(cancellationToken)) { var result = await DataReader.ToEnumerableAsync(reader, dbFields, connection.GetDbSetting()); @@ -605,6 +614,7 @@ private static IEnumerable ExecuteQueryInternalForType(this ID /// The command timeout in seconds to be used. /// The transaction to be used. /// The cache object to be used. + /// The object to be used during the asynchronous operation. /// /// An enumerable list of the target result type instances containing the converted results of the underlying object. /// @@ -616,7 +626,8 @@ public static Task> ExecuteQueryAsync(this IDbConn int? cacheItemExpiration = Constant.DefaultCacheItemExpirationInMinutes, int? commandTimeout = null, IDbTransaction transaction = null, - ICache cache = null) + ICache cache = null, + CancellationToken cancellationToken = default) { return ExecuteQueryAsyncInternal(connection: connection, commandText: commandText, @@ -626,6 +637,7 @@ public static Task> ExecuteQueryAsync(this IDbConn cacheItemExpiration: cacheItemExpiration, commandTimeout: commandTimeout, transaction: transaction, + cancellationToken: cancellationToken, cache: cache, tableName: ClassMappedNameCache.Get(), skipCommandArrayParametersCheck: false); @@ -643,6 +655,7 @@ public static Task> ExecuteQueryAsync(this IDbConn /// /// /// + /// /// /// /// @@ -656,6 +669,7 @@ internal static Task> ExecuteQueryAsyncInternal(th int? commandTimeout = null, IDbTransaction transaction = null, ICache cache = null, + CancellationToken cancellationToken = default, string tableName = null, bool skipCommandArrayParametersCheck = true) { @@ -684,6 +698,7 @@ internal static Task> ExecuteQueryAsyncInternal(th commandTimeout: commandTimeout, transaction: transaction, cache: cache, + cancellationToken: cancellationToken, tableName: tableName, skipCommandArrayParametersCheck: skipCommandArrayParametersCheck); } @@ -698,6 +713,7 @@ internal static Task> ExecuteQueryAsyncInternal(th commandTimeout: commandTimeout, transaction: transaction, cache: cache, + cancellationToken: cancellationToken, tableName: tableName, skipCommandArrayParametersCheck: skipCommandArrayParametersCheck); } @@ -715,6 +731,7 @@ internal static Task> ExecuteQueryAsyncInternal(th /// /// /// + /// /// /// /// @@ -728,6 +745,7 @@ private static async Task> ExecuteQueryAsyncInternalForDict int? commandTimeout = null, IDbTransaction transaction = null, ICache cache = null, + CancellationToken cancellationToken = default, string tableName = null, bool skipCommandArrayParametersCheck = true) { @@ -751,6 +769,7 @@ private static async Task> ExecuteQueryAsyncInternalForDict commandTimeout: commandTimeout, transaction: transaction, cache: null, + cancellationToken: cancellationToken, tableName: tableName, skipCommandArrayParametersCheck: skipCommandArrayParametersCheck)).OfTargetType(); @@ -777,6 +796,7 @@ private static async Task> ExecuteQueryAsyncInternalForDict /// /// /// + /// /// /// /// @@ -789,6 +809,7 @@ private static async Task> ExecuteQueryAsyncInternalForType int? commandTimeout = null, IDbTransaction transaction = null, ICache cache = null, + CancellationToken cancellationToken = default, string tableName = null, bool skipCommandArrayParametersCheck = true) { @@ -804,7 +825,7 @@ private static async Task> ExecuteQueryAsyncInternalForType // DB Fields var dbFields = !string.IsNullOrWhiteSpace(tableName) ? - await DbFieldCache.GetAsync(connection, tableName, transaction, false) : null; + await DbFieldCache.GetAsync(connection, tableName, transaction, false, cancellationToken) : null; // Execute the actual method using (var command = await CreateDbCommandForExecutionAsync(connection: connection, @@ -813,11 +834,12 @@ private static async Task> ExecuteQueryAsyncInternalForType commandType: commandType, commandTimeout: commandTimeout, transaction: transaction, + cancellationToken: cancellationToken, entityType: typeof(TResult), dbFields: dbFields, skipCommandArrayParametersCheck: skipCommandArrayParametersCheck)) { - using (var reader = await command.ExecuteReaderAsync()) + using (var reader = await command.ExecuteReaderAsync(cancellationToken)) { var result = await DataReader.ToEnumerableAsync(reader, dbFields, connection.GetDbSetting()); @@ -885,13 +907,15 @@ public static QueryMultipleExtractor ExecuteQueryMultiple(this IDbConnection con /// The command type to be used. /// The command timeout in seconds to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An instance of used to extract the results. public static async Task ExecuteQueryMultipleAsync(this IDbConnection connection, string commandText, object param = null, CommandType? commandType = null, int? commandTimeout = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Call var reader = await ExecuteReaderAsyncInternal(connection: connection, @@ -900,12 +924,13 @@ public static async Task ExecuteQueryMultipleAsync(this commandType: commandType, commandTimeout: commandTimeout, transaction: transaction, + cancellationToken: cancellationToken, entityType: null, dbFields: null, skipCommandArrayParametersCheck: false); // Return - return new QueryMultipleExtractor((DbDataReader)reader); + return new QueryMultipleExtractor((DbDataReader)reader, cancellationToken); } #endregion @@ -1016,13 +1041,15 @@ internal static IDataReader ExecuteReaderInternal(this IDbConnection connection, /// The command type to be used. /// The command timeout in seconds to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The instance of the object. public static Task ExecuteReaderAsync(this IDbConnection connection, string commandText, object param = null, CommandType? commandType = null, int? commandTimeout = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return ExecuteReaderAsyncInternal(connection: connection, commandText: commandText, @@ -1030,6 +1057,7 @@ public static Task ExecuteReaderAsync(this IDbConnection connection commandType: commandType, commandTimeout: commandTimeout, transaction: transaction, + cancellationToken: cancellationToken, entityType: null, dbFields: null, skipCommandArrayParametersCheck: false); @@ -1044,6 +1072,7 @@ public static Task ExecuteReaderAsync(this IDbConnection connection /// /// /// + /// /// /// /// @@ -1054,6 +1083,7 @@ internal static async Task ExecuteReaderAsyncInternal(this IDbConne CommandType? commandType, int? commandTimeout, IDbTransaction transaction, + CancellationToken cancellationToken, Type entityType, IEnumerable dbFields, bool skipCommandArrayParametersCheck) @@ -1066,6 +1096,7 @@ internal static async Task ExecuteReaderAsyncInternal(this IDbConne commandType: commandType, commandTimeout: commandTimeout, transaction: transaction, + cancellationToken: cancellationToken, entityType: entityType, dbFields: dbFields, skipCommandArrayParametersCheck: skipCommandArrayParametersCheck); @@ -1074,7 +1105,7 @@ internal static async Task ExecuteReaderAsyncInternal(this IDbConne // Ensure the DbCommand disposal try { - return await command.ExecuteReaderAsync(); + return await command.ExecuteReaderAsync(cancellationToken); } catch { @@ -1180,13 +1211,15 @@ internal static int ExecuteNonQueryInternal(this IDbConnection connection, /// The command type to be used. /// The command timeout in seconds to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static Task ExecuteNonQueryAsync(this IDbConnection connection, string commandText, object param = null, CommandType? commandType = null, int? commandTimeout = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return ExecuteNonQueryAsyncInternal(connection: connection, commandText: commandText, @@ -1194,6 +1227,7 @@ public static Task ExecuteNonQueryAsync(this IDbConnection connection, commandType: commandType, commandTimeout: commandTimeout, transaction: transaction, + cancellationToken: cancellationToken, entityType: null, dbFields: null, skipCommandArrayParametersCheck: false); @@ -1208,6 +1242,7 @@ public static Task ExecuteNonQueryAsync(this IDbConnection connection, /// /// /// + /// /// /// /// @@ -1218,6 +1253,7 @@ internal static async Task ExecuteNonQueryAsyncInternal(this IDbConnection CommandType? commandType, int? commandTimeout, IDbTransaction transaction, + CancellationToken cancellationToken, Type entityType, IEnumerable dbFields, bool skipCommandArrayParametersCheck) @@ -1228,11 +1264,12 @@ internal static async Task ExecuteNonQueryAsyncInternal(this IDbConnection commandType: commandType, commandTimeout: commandTimeout, transaction: transaction, + cancellationToken: cancellationToken, entityType: entityType, dbFields: dbFields, skipCommandArrayParametersCheck: skipCommandArrayParametersCheck)) { - return await command.ExecuteNonQueryAsync(); + return await command.ExecuteNonQueryAsync(cancellationToken); } } @@ -1326,13 +1363,15 @@ internal static object ExecuteScalarInternal(this IDbConnection connection, /// The command type to be used. /// The command timeout in seconds to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An object that holds the first occurence value (first column of first row) of the execution. public static Task ExecuteScalarAsync(this IDbConnection connection, string commandText, object param = null, CommandType? commandType = null, int? commandTimeout = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return ExecuteScalarAsyncInternal(connection: connection, commandText: commandText, @@ -1340,6 +1379,7 @@ public static Task ExecuteScalarAsync(this IDbConnection connection, commandType: commandType, commandTimeout: commandTimeout, transaction: transaction, + cancellationToken: cancellationToken, entityType: null, dbFields: null, skipCommandArrayParametersCheck: false); @@ -1354,6 +1394,7 @@ public static Task ExecuteScalarAsync(this IDbConnection connection, /// /// /// + /// /// /// /// @@ -1364,6 +1405,7 @@ internal static async Task ExecuteScalarAsyncInternal(this IDbConnection CommandType? commandType, int? commandTimeout, IDbTransaction transaction, + CancellationToken cancellationToken, Type entityType, IEnumerable dbFields, bool skipCommandArrayParametersCheck) @@ -1374,11 +1416,12 @@ internal static async Task ExecuteScalarAsyncInternal(this IDbConnection commandType: commandType, commandTimeout: commandTimeout, transaction: transaction, + cancellationToken: cancellationToken, entityType: entityType, dbFields: dbFields, skipCommandArrayParametersCheck: skipCommandArrayParametersCheck)) { - return Converter.DbNullToNull(await command.ExecuteScalarAsync()); + return Converter.DbNullToNull(await command.ExecuteScalarAsync(cancellationToken)); } } @@ -1475,13 +1518,15 @@ internal static TResult ExecuteScalarInternal(this IDbConnection connec /// The command type to be used. /// The command timeout in seconds to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// A first occurence value (first column of first row) of the execution. public static Task ExecuteScalarAsync(this IDbConnection connection, string commandText, object param = null, CommandType? commandType = null, int? commandTimeout = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return ExecuteScalarAsyncInternal(connection: connection, commandText: commandText, @@ -1489,6 +1534,7 @@ public static Task ExecuteScalarAsync(this IDbConnection conne commandType: commandType, commandTimeout: commandTimeout, transaction: transaction, + cancellationToken: cancellationToken, entityType: null, dbFields: null, skipCommandArrayParametersCheck: false); @@ -1504,6 +1550,7 @@ public static Task ExecuteScalarAsync(this IDbConnection conne /// /// /// + /// /// /// /// @@ -1514,6 +1561,7 @@ internal static async Task ExecuteScalarAsyncInternal(this IDb CommandType? commandType, int? commandTimeout, IDbTransaction transaction, + CancellationToken cancellationToken, Type entityType, IEnumerable dbFields, bool skipCommandArrayParametersCheck) @@ -1524,11 +1572,12 @@ internal static async Task ExecuteScalarAsyncInternal(this IDb commandType: commandType, commandTimeout: commandTimeout, transaction: transaction, + cancellationToken: cancellationToken, entityType: entityType, dbFields: dbFields, skipCommandArrayParametersCheck: skipCommandArrayParametersCheck)) { - return Converter.ToType(await command.ExecuteScalarAsync()); + return Converter.ToType(await command.ExecuteScalarAsync(cancellationToken)); } } @@ -1674,11 +1723,13 @@ internal static ClassProperty GetAndGuardPrimaryKeyOrIdentityKey(IDbConnection c /// /// /// + /// /// internal static Task GetAndGuardPrimaryKeyOrIdentityKeyAsync(IDbConnection connection, - IDbTransaction transaction) + IDbTransaction transaction, + CancellationToken cancellationToken = default) where TEntity : class => - GetAndGuardPrimaryKeyOrIdentityKeyAsync(connection, ClassMappedNameCache.Get(), transaction); + GetAndGuardPrimaryKeyOrIdentityKeyAsync(connection, ClassMappedNameCache.Get(), transaction, cancellationToken); /// /// @@ -1687,12 +1738,14 @@ internal static Task GetAndGuardPrimaryKeyOrIdentityKeyAsync /// /// + /// /// internal static Task GetAndGuardPrimaryKeyOrIdentityKeyAsync(IDbConnection connection, string tableName, - IDbTransaction transaction) + IDbTransaction transaction, + CancellationToken cancellationToken = default) where TEntity : class => - GetAndGuardPrimaryKeyOrIdentityKeyAsync(connection, tableName, transaction, typeof(TEntity)); + GetAndGuardPrimaryKeyOrIdentityKeyAsync(connection, tableName, transaction, typeof(TEntity), cancellationToken); /// /// @@ -1701,13 +1754,15 @@ internal static Task GetAndGuardPrimaryKeyOrIdentityKeyAsync /// /// + /// /// internal static async Task GetAndGuardPrimaryKeyOrIdentityKeyAsync(IDbConnection connection, string tableName, IDbTransaction transaction, - Type entityType) + Type entityType, + CancellationToken cancellationToken = default) { - var dbFields = await DbFieldCache.GetAsync(connection, tableName, transaction); + var dbFields = await DbFieldCache.GetAsync(connection, tableName, transaction, cancellationToken); var property = GetAndGuardPrimaryKeyOrIdentityKey(entityType, dbFields); if (property == null) { @@ -1801,12 +1856,14 @@ internal static DbField GetAndGuardPrimaryKeyOrIdentityKey(IDbConnection connect /// /// /// + /// /// internal static async Task GetAndGuardPrimaryKeyOrIdentityKeyAsync(IDbConnection connection, string tableName, - IDbTransaction transaction) + IDbTransaction transaction, + CancellationToken cancellationToken = default) { - var dbFields = await DbFieldCache.GetAsync(connection, tableName, transaction); + var dbFields = await DbFieldCache.GetAsync(connection, tableName, transaction, cancellationToken); var dbField = dbFields?.FirstOrDefault(df => df.IsPrimary == true) ?? dbFields?.FirstOrDefault(df => df.IsIdentity == true); return GetAndGuardPrimaryKeyOrIdentityKey(tableName, dbField); } @@ -1875,11 +1932,13 @@ internal static QueryGroup WhatToQueryGroup(this IDbConnection connection, /// /// /// + /// /// internal static async Task WhatToQueryGroupAsync(this IDbConnection connection, string tableName, T what, - IDbTransaction transaction) + IDbTransaction transaction, + CancellationToken cancellationToken = default) { if (what == null) { @@ -1891,12 +1950,12 @@ internal static async Task WhatToQueryGroupAsync(this IDbConnecti var whatType = what?.GetType(); if (whatType.IsClassType() || whatType.IsAnonymousType()) { - var classProperty = await GetAndGuardPrimaryKeyOrIdentityKeyAsync(connection, tableName, transaction, whatType); + var classProperty = await GetAndGuardPrimaryKeyOrIdentityKeyAsync(connection, tableName, transaction, whatType, cancellationToken); queryGroup = WhatToQueryGroup(classProperty, what); } else { - var dbField = await GetAndGuardPrimaryKeyOrIdentityKeyAsync(connection, tableName, transaction); + var dbField = await GetAndGuardPrimaryKeyOrIdentityKeyAsync(connection, tableName, transaction, cancellationToken); queryGroup = WhatToQueryGroup(dbField, what); } } @@ -1959,10 +2018,12 @@ internal static QueryGroup WhatToQueryGroup(IDbConnection connection, /// /// /// + /// /// internal static async Task WhatToQueryGroupAsync(IDbConnection connection, object what, - IDbTransaction transaction) + IDbTransaction transaction, + CancellationToken cancellationToken = default) where TEntity : class { if (what == null) @@ -1974,7 +2035,7 @@ internal static async Task WhatToQueryGroupAsync(IDbConnect { return queryGroup; } - var key = await GetAndGuardPrimaryKeyOrIdentityKeyAsync(connection, ClassMappedNameCache.Get(), transaction); + var key = await GetAndGuardPrimaryKeyOrIdentityKeyAsync(connection, ClassMappedNameCache.Get(), transaction, cancellationToken); return WhatToQueryGroup(key, what); } @@ -2401,6 +2462,7 @@ internal static DbCommand CreateDbCommandForExecution(this IDbConnection connect /// /// /// + /// /// /// /// @@ -2411,6 +2473,7 @@ internal static async Task CreateDbCommandForExecutionAsync(this IDbC CommandType? commandType = null, int? commandTimeout = null, IDbTransaction transaction = null, + CancellationToken cancellationToken = default, Type entityType = null, IEnumerable dbFields = null, bool skipCommandArrayParametersCheck = true) @@ -2419,7 +2482,7 @@ internal static async Task CreateDbCommandForExecutionAsync(this IDbC ValidateTransactionConnectionObject(connection, transaction); // Open - await connection.EnsureOpenAsync(); + await connection.EnsureOpenAsync(cancellationToken); // Call return CreateDbCommandForExecutionInternal(connection: connection, diff --git a/RepoDb.Core/RepoDb/Interfaces/IDbHelper.cs b/RepoDb.Core/RepoDb/Interfaces/IDbHelper.cs index d42202cd2..23b3f372f 100644 --- a/RepoDb.Core/RepoDb/Interfaces/IDbHelper.cs +++ b/RepoDb.Core/RepoDb/Interfaces/IDbHelper.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Data; +using System.Threading; using System.Threading.Tasks; namespace RepoDb.Interfaces @@ -34,10 +35,12 @@ IEnumerable GetFields(IDbConnection connection, /// The instance of the connection object. /// The name of the target table. /// The transaction object that is currently in used. + /// A to observe while waiting for the task to complete. /// A list of of the target table. Task> GetFieldsAsync(IDbConnection connection, string tableName, - IDbTransaction transaction = null); + IDbTransaction transaction = null, + CancellationToken cancellationToken = default); #endregion @@ -57,9 +60,11 @@ object GetScopeIdentity(IDbConnection connection, /// /// The instance of the connection object. /// The transaction object that is currently in used. + /// The object to be used during the asynchronous operation. /// The newly generated identity from the database. Task GetScopeIdentityAsync(IDbConnection connection, - IDbTransaction transaction = null); + IDbTransaction transaction = null, + CancellationToken cancellationToken = default); #endregion } diff --git a/RepoDb.Core/RepoDb/Operations/BaseRepository/Average.cs b/RepoDb.Core/RepoDb/Operations/BaseRepository/Average.cs index ddb2a742f..c7d9053fa 100644 --- a/RepoDb.Core/RepoDb/Operations/BaseRepository/Average.cs +++ b/RepoDb.Core/RepoDb/Operations/BaseRepository/Average.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Data; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -404,16 +405,19 @@ public TResult Average(Expression> field, /// The dynamic expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public Task AverageAsync(Field field, object where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.AverageAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -423,16 +427,19 @@ public Task AverageAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public Task AverageAsync(Field field, Expression> where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.AverageAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -442,16 +449,19 @@ public Task AverageAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public Task AverageAsync(Field field, QueryField where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.AverageAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -461,16 +471,19 @@ public Task AverageAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public Task AverageAsync(Field field, IEnumerable where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.AverageAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -480,16 +493,19 @@ public Task AverageAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public Task AverageAsync(Field field, QueryGroup where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.AverageAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -499,16 +515,19 @@ public Task AverageAsync(Field field, /// The dynamic expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public Task AverageAsync(Expression> field, object where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.AverageAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -518,16 +537,19 @@ public Task AverageAsync(Expression> field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public Task AverageAsync(Expression> field, Expression> where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.AverageAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -537,16 +559,19 @@ public Task AverageAsync(Expression> field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public Task AverageAsync(Expression> field, QueryField where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.AverageAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -556,16 +581,19 @@ public Task AverageAsync(Expression> field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public Task AverageAsync(Expression> field, IEnumerable where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.AverageAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -575,16 +603,19 @@ public Task AverageAsync(Expression> field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public Task AverageAsync(Expression> field, QueryGroup where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.AverageAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -594,16 +625,19 @@ public Task AverageAsync(Expression> field, /// The dynamic expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public Task AverageAsync(Field field, object where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.AverageAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -613,16 +647,19 @@ public Task AverageAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public Task AverageAsync(Field field, Expression> where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.AverageAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -632,16 +669,19 @@ public Task AverageAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public Task AverageAsync(Field field, QueryField where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.AverageAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -651,16 +691,19 @@ public Task AverageAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public Task AverageAsync(Field field, IEnumerable where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.AverageAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -670,16 +713,19 @@ public Task AverageAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public Task AverageAsync(Field field, QueryGroup where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.AverageAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -689,16 +735,19 @@ public Task AverageAsync(Field field, /// The dynamic expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public Task AverageAsync(Expression> field, object where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.AverageAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -708,16 +757,19 @@ public Task AverageAsync(Expression> fi /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public Task AverageAsync(Expression> field, Expression> where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.AverageAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -727,16 +779,19 @@ public Task AverageAsync(Expression> fi /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public Task AverageAsync(Expression> field, QueryField where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.AverageAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -746,16 +801,19 @@ public Task AverageAsync(Expression> fi /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public Task AverageAsync(Expression> field, IEnumerable where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.AverageAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -765,16 +823,19 @@ public Task AverageAsync(Expression> fi /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public Task AverageAsync(Expression> field, QueryGroup where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.AverageAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } #endregion diff --git a/RepoDb.Core/RepoDb/Operations/BaseRepository/AverageAll.cs b/RepoDb.Core/RepoDb/Operations/BaseRepository/AverageAll.cs index cfb2f7681..f90d3eaed 100644 --- a/RepoDb.Core/RepoDb/Operations/BaseRepository/AverageAll.cs +++ b/RepoDb.Core/RepoDb/Operations/BaseRepository/AverageAll.cs @@ -1,6 +1,7 @@ using System; using System.Data; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -88,14 +89,17 @@ public TResult AverageAll(Expression> field, /// The field to be averaged. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public Task AverageAllAsync(Field field, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.AverageAllAsync(field: field, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -104,14 +108,17 @@ public Task AverageAllAsync(Field field, /// The field to be averaged. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public Task AverageAllAsync(Expression> field, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.AverageAllAsync(field: field, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -121,14 +128,17 @@ public Task AverageAllAsync(Expression> field, /// The field to be averaged. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public Task AverageAllAsync(Field field, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.AverageAllAsync(field: field, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -138,14 +148,17 @@ public Task AverageAllAsync(Field field, /// The field to be averaged. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public Task AverageAllAsync(Expression> field, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.AverageAllAsync(field: field, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } #endregion diff --git a/RepoDb.Core/RepoDb/Operations/BaseRepository/BatchQuery.cs b/RepoDb.Core/RepoDb/Operations/BaseRepository/BatchQuery.cs index db511fff6..2a63b9d1b 100644 --- a/RepoDb.Core/RepoDb/Operations/BaseRepository/BatchQuery.cs +++ b/RepoDb.Core/RepoDb/Operations/BaseRepository/BatchQuery.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Data; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -374,6 +375,7 @@ public IEnumerable BatchQuery(int page, /// The list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public Task> BatchQueryAsync(string tableName, int page, @@ -381,7 +383,8 @@ public Task> BatchQueryAsync(string tableName, IEnumerable orderBy, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.BatchQueryAsync(tableName: tableName, page: page, @@ -389,7 +392,8 @@ public Task> BatchQueryAsync(string tableName, orderBy: orderBy, fields: fields, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -403,6 +407,7 @@ public Task> BatchQueryAsync(string tableName, /// The list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public Task> BatchQueryAsync(string tableName, int page, @@ -411,7 +416,8 @@ public Task> BatchQueryAsync(string tableName, object where = null, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.BatchQueryAsync(tableName: tableName, page: page, @@ -420,7 +426,8 @@ public Task> BatchQueryAsync(string tableName, where: where, fields: fields, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -434,6 +441,7 @@ public Task> BatchQueryAsync(string tableName, /// The list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public Task> BatchQueryAsync(string tableName, int page, @@ -442,7 +450,8 @@ public Task> BatchQueryAsync(string tableName, Expression> where = null, string hints = null, IEnumerable fields = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.BatchQueryAsync(tableName: tableName, page: page, @@ -451,7 +460,8 @@ public Task> BatchQueryAsync(string tableName, where: where, fields: fields, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -465,6 +475,7 @@ public Task> BatchQueryAsync(string tableName, /// The list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public Task> BatchQueryAsync(string tableName, int page, @@ -473,7 +484,8 @@ public Task> BatchQueryAsync(string tableName, QueryField where = null, string hints = null, IEnumerable fields = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.BatchQueryAsync(tableName: tableName, page: page, @@ -482,7 +494,8 @@ public Task> BatchQueryAsync(string tableName, where: where, fields: fields, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -496,6 +509,7 @@ public Task> BatchQueryAsync(string tableName, /// The list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public Task> BatchQueryAsync(string tableName, int page, @@ -504,7 +518,8 @@ public Task> BatchQueryAsync(string tableName, IEnumerable where = null, string hints = null, IEnumerable fields = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.BatchQueryAsync(tableName: tableName, page: page, @@ -513,7 +528,8 @@ public Task> BatchQueryAsync(string tableName, where: where, fields: fields, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -527,6 +543,7 @@ public Task> BatchQueryAsync(string tableName, /// The list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public Task> BatchQueryAsync(string tableName, int page, @@ -535,7 +552,8 @@ public Task> BatchQueryAsync(string tableName, QueryGroup where = null, string hints = null, IEnumerable fields = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.BatchQueryAsync(tableName: tableName, page: page, @@ -544,7 +562,8 @@ public Task> BatchQueryAsync(string tableName, where: where, fields: fields, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -556,20 +575,23 @@ public Task> BatchQueryAsync(string tableName, /// The list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public Task> BatchQueryAsync(int page, int rowsPerBatch, IEnumerable orderBy, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.BatchQueryAsync(page: page, rowsPerBatch: rowsPerBatch, orderBy: orderBy, fields: fields, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -582,6 +604,7 @@ public Task> BatchQueryAsync(int page, /// The list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public Task> BatchQueryAsync(int page, int rowsPerBatch, @@ -589,7 +612,8 @@ public Task> BatchQueryAsync(int page, object where = null, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.BatchQueryAsync(page: page, rowsPerBatch: rowsPerBatch, @@ -597,7 +621,8 @@ public Task> BatchQueryAsync(int page, where: where, fields: fields, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -610,6 +635,7 @@ public Task> BatchQueryAsync(int page, /// The list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public Task> BatchQueryAsync(int page, int rowsPerBatch, @@ -617,7 +643,8 @@ public Task> BatchQueryAsync(int page, Expression> where = null, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.BatchQueryAsync(page: page, rowsPerBatch: rowsPerBatch, @@ -625,7 +652,8 @@ public Task> BatchQueryAsync(int page, where: where, fields: fields, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -638,6 +666,7 @@ public Task> BatchQueryAsync(int page, /// The list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public Task> BatchQueryAsync(int page, int rowsPerBatch, @@ -645,7 +674,8 @@ public Task> BatchQueryAsync(int page, QueryField where = null, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.BatchQueryAsync(page: page, rowsPerBatch: rowsPerBatch, @@ -653,7 +683,8 @@ public Task> BatchQueryAsync(int page, where: where, fields: fields, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -666,6 +697,7 @@ public Task> BatchQueryAsync(int page, /// The list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public Task> BatchQueryAsync(int page, int rowsPerBatch, @@ -673,7 +705,8 @@ public Task> BatchQueryAsync(int page, IEnumerable where = null, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.BatchQueryAsync(page: page, rowsPerBatch: rowsPerBatch, @@ -681,7 +714,8 @@ public Task> BatchQueryAsync(int page, where: where, fields: fields, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -694,6 +728,7 @@ public Task> BatchQueryAsync(int page, /// The list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public Task> BatchQueryAsync(int page, int rowsPerBatch, @@ -701,7 +736,8 @@ public Task> BatchQueryAsync(int page, QueryGroup where = null, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.BatchQueryAsync(page: page, rowsPerBatch: rowsPerBatch, @@ -709,7 +745,8 @@ public Task> BatchQueryAsync(int page, where: where, fields: fields, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } #endregion diff --git a/RepoDb.Core/RepoDb/Operations/BaseRepository/Count.cs b/RepoDb.Core/RepoDb/Operations/BaseRepository/Count.cs index cb4ced3a8..978a8f002 100644 --- a/RepoDb.Core/RepoDb/Operations/BaseRepository/Count.cs +++ b/RepoDb.Core/RepoDb/Operations/BaseRepository/Count.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Data; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -103,14 +104,17 @@ public long Count(QueryGroup where = null, /// The dynamic expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An integer value that holds the number of rows from the table. public Task CountAsync(object where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.CountAsync(where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -119,14 +123,17 @@ public Task CountAsync(object where = null, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An integer value that holds the number of rows from the table. public Task CountAsync(Expression> where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.CountAsync(where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -135,14 +142,17 @@ public Task CountAsync(Expression> where = null, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An integer value that holds the number of rows from the table. public Task CountAsync(QueryField where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.CountAsync(where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -151,14 +161,17 @@ public Task CountAsync(QueryField where = null, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An integer value that holds the number of rows from the table. public Task CountAsync(IEnumerable where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.CountAsync(where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -167,14 +180,17 @@ public Task CountAsync(IEnumerable where = null, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An integer value that holds the number of rows from the table. public Task CountAsync(QueryGroup where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.CountAsync(where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } #endregion diff --git a/RepoDb.Core/RepoDb/Operations/BaseRepository/CountAll.cs b/RepoDb.Core/RepoDb/Operations/BaseRepository/CountAll.cs index 569a16ba6..a8274be56 100644 --- a/RepoDb.Core/RepoDb/Operations/BaseRepository/CountAll.cs +++ b/RepoDb.Core/RepoDb/Operations/BaseRepository/CountAll.cs @@ -1,5 +1,6 @@ using System; using System.Data; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -33,12 +34,15 @@ public long CountAll(string hints = null, /// /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An integer value that holds the number of rows from the table. public Task CountAllAsync(string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.CountAllAsync(hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } #endregion diff --git a/RepoDb.Core/RepoDb/Operations/BaseRepository/Delete.cs b/RepoDb.Core/RepoDb/Operations/BaseRepository/Delete.cs index 38ed43814..dcd1a74a7 100644 --- a/RepoDb.Core/RepoDb/Operations/BaseRepository/Delete.cs +++ b/RepoDb.Core/RepoDb/Operations/BaseRepository/Delete.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Data; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -136,14 +137,17 @@ public int Delete(QueryGroup where, /// The data entity object to be deleted. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. public Task DeleteAsync(TEntity entity, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.DeleteAsync(entity: entity, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -153,14 +157,17 @@ public Task DeleteAsync(TEntity entity, /// The dynamic expression or the key value to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. public Task DeleteAsync(TWhat what, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.DeleteAsync(what: what, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -169,14 +176,17 @@ public Task DeleteAsync(TWhat what, /// The dynamic expression or the key value to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. public Task DeleteAsync(object what, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.DeleteAsync(what: what, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -185,14 +195,17 @@ public Task DeleteAsync(object what, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. public Task DeleteAsync(Expression> where, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.DeleteAsync(where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -201,14 +214,17 @@ public Task DeleteAsync(Expression> where, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. public Task DeleteAsync(QueryField where, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.DeleteAsync(where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -217,14 +233,17 @@ public Task DeleteAsync(QueryField where, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. public Task DeleteAsync(IEnumerable where, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.DeleteAsync(where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -233,14 +252,17 @@ public Task DeleteAsync(IEnumerable where, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. public Task DeleteAsync(QueryGroup where, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.DeleteAsync(where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } #endregion diff --git a/RepoDb.Core/RepoDb/Operations/BaseRepository/DeleteAll.cs b/RepoDb.Core/RepoDb/Operations/BaseRepository/DeleteAll.cs index 90bb5e1c0..990c6cb68 100644 --- a/RepoDb.Core/RepoDb/Operations/BaseRepository/DeleteAll.cs +++ b/RepoDb.Core/RepoDb/Operations/BaseRepository/DeleteAll.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Data; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -84,14 +85,17 @@ public int DeleteAll(string hints = null, /// The list of data entity objects to be deleted. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. public Task DeleteAllAsync(IEnumerable entities, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.DeleteAllAsync(entities: entities, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -101,14 +105,17 @@ public Task DeleteAllAsync(IEnumerable entities, /// The list of the keys to be deleted. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. public Task DeleteAllAsync(IEnumerable keys, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.DeleteAllAsync(keys: keys, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -117,14 +124,17 @@ public Task DeleteAllAsync(IEnumerable keys, /// The list of the keys to be deleted. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. public Task DeleteAllAsync(IEnumerable keys, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.DeleteAllAsync(keys: keys, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -132,11 +142,15 @@ public Task DeleteAllAsync(IEnumerable keys, /// /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. public Task DeleteAllAsync(string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { - return DbRepository.DeleteAllAsync(); + return DbRepository.DeleteAllAsync(hints: hints, + transaction: transaction, + cancellationToken: cancellationToken); } #endregion diff --git a/RepoDb.Core/RepoDb/Operations/BaseRepository/Exists.cs b/RepoDb.Core/RepoDb/Operations/BaseRepository/Exists.cs index 4f06db0b6..4c8366dcc 100644 --- a/RepoDb.Core/RepoDb/Operations/BaseRepository/Exists.cs +++ b/RepoDb.Core/RepoDb/Operations/BaseRepository/Exists.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Data; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -103,14 +104,17 @@ public bool Exists(QueryGroup where, /// The dynamic expression or the key value to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// A boolean value that indicates whether the rows are existing in the table. public Task ExistsAsync(object what, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.ExistsAsync(what: what, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -120,14 +124,17 @@ public Task ExistsAsync(object what, /// The dynamic expression or the key value to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// A boolean value that indicates whether the rows are existing in the table. public Task ExistsAsync(TWhat what, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.ExistsAsync(what: what, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -136,14 +143,17 @@ public Task ExistsAsync(TWhat what, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// A boolean value that indicates whether the rows are existing in the table. public Task ExistsAsync(Expression> where, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.ExistsAsync(where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -152,14 +162,17 @@ public Task ExistsAsync(Expression> where, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// A boolean value that indicates whether the rows are existing in the table. public Task ExistsAsync(QueryField where, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.ExistsAsync(where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -168,14 +181,17 @@ public Task ExistsAsync(QueryField where, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// A boolean value that indicates whether the rows are existing in the table. public Task ExistsAsync(IEnumerable where, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.ExistsAsync(where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -184,14 +200,17 @@ public Task ExistsAsync(IEnumerable where, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// A boolean value that indicates whether the rows are existing in the table. public Task ExistsAsync(QueryGroup where, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.ExistsAsync(where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } #endregion diff --git a/RepoDb.Core/RepoDb/Operations/BaseRepository/Insert.cs b/RepoDb.Core/RepoDb/Operations/BaseRepository/Insert.cs index d742a8822..2a3c8f8ea 100644 --- a/RepoDb.Core/RepoDb/Operations/BaseRepository/Insert.cs +++ b/RepoDb.Core/RepoDb/Operations/BaseRepository/Insert.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Data; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -62,16 +63,19 @@ public TResult Insert(TEntity entity, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public Task InsertAsync(TEntity entity, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.InsertAsync(entity: entity, fields: fields, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -82,16 +86,19 @@ public Task InsertAsync(TEntity entity, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public Task InsertAsync(TEntity entity, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.InsertAsync(entity: entity, fields: fields, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } #endregion diff --git a/RepoDb.Core/RepoDb/Operations/BaseRepository/InsertAll.cs b/RepoDb.Core/RepoDb/Operations/BaseRepository/InsertAll.cs index deb39c2fd..8b20fb885 100644 --- a/RepoDb.Core/RepoDb/Operations/BaseRepository/InsertAll.cs +++ b/RepoDb.Core/RepoDb/Operations/BaseRepository/InsertAll.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Data; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -46,18 +47,21 @@ public int InsertAll(IEnumerable entities, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of inserted rows in the table. public Task InsertAllAsync(IEnumerable entities, int batchSize = Constant.DefaultBatchOperationSize, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.InsertAllAsync(entities: entities, batchSize: batchSize, fields: fields, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } #endregion diff --git a/RepoDb.Core/RepoDb/Operations/BaseRepository/Max.cs b/RepoDb.Core/RepoDb/Operations/BaseRepository/Max.cs index 5ee4e4d83..9870b5903 100644 --- a/RepoDb.Core/RepoDb/Operations/BaseRepository/Max.cs +++ b/RepoDb.Core/RepoDb/Operations/BaseRepository/Max.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Data; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -404,16 +405,19 @@ public TResult Max(Expression> field, /// The dynamic expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public Task MaxAsync(Field field, object where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MaxAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -423,16 +427,19 @@ public Task MaxAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public Task MaxAsync(Field field, Expression> where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MaxAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -442,16 +449,19 @@ public Task MaxAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public Task MaxAsync(Field field, QueryField where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MaxAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -461,16 +471,19 @@ public Task MaxAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public Task MaxAsync(Field field, IEnumerable where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MaxAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -480,16 +493,19 @@ public Task MaxAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public Task MaxAsync(Field field, QueryGroup where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MaxAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -499,16 +515,19 @@ public Task MaxAsync(Field field, /// The dynamic expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public Task MaxAsync(Expression> field, object where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MaxAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -518,16 +537,19 @@ public Task MaxAsync(Expression> field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public Task MaxAsync(Expression> field, Expression> where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MaxAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -537,16 +559,19 @@ public Task MaxAsync(Expression> field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public Task MaxAsync(Expression> field, QueryField where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MaxAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -556,16 +581,19 @@ public Task MaxAsync(Expression> field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public Task MaxAsync(Expression> field, IEnumerable where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MaxAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -575,16 +603,19 @@ public Task MaxAsync(Expression> field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public Task MaxAsync(Expression> field, QueryGroup where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MaxAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -594,16 +625,19 @@ public Task MaxAsync(Expression> field, /// The dynamic expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public Task MaxAsync(Field field, object where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MaxAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -613,16 +647,19 @@ public Task MaxAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public Task MaxAsync(Field field, Expression> where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MaxAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -632,16 +669,19 @@ public Task MaxAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public Task MaxAsync(Field field, QueryField where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MaxAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -651,16 +691,19 @@ public Task MaxAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public Task MaxAsync(Field field, IEnumerable where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MaxAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -670,16 +713,19 @@ public Task MaxAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public Task MaxAsync(Field field, QueryGroup where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MaxAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -689,16 +735,19 @@ public Task MaxAsync(Field field, /// The dynamic expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public Task MaxAsync(Expression> field, object where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MaxAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -708,16 +757,19 @@ public Task MaxAsync(Expression> field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public Task MaxAsync(Expression> field, Expression> where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MaxAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -727,16 +779,19 @@ public Task MaxAsync(Expression> field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public Task MaxAsync(Expression> field, QueryField where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MaxAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -746,16 +801,19 @@ public Task MaxAsync(Expression> field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public Task MaxAsync(Expression> field, IEnumerable where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MaxAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -765,16 +823,19 @@ public Task MaxAsync(Expression> field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public Task MaxAsync(Expression> field, QueryGroup where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MaxAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } #endregion diff --git a/RepoDb.Core/RepoDb/Operations/BaseRepository/MaxAll.cs b/RepoDb.Core/RepoDb/Operations/BaseRepository/MaxAll.cs index a0ee021b1..f7133157f 100644 --- a/RepoDb.Core/RepoDb/Operations/BaseRepository/MaxAll.cs +++ b/RepoDb.Core/RepoDb/Operations/BaseRepository/MaxAll.cs @@ -1,6 +1,7 @@ using System; using System.Data; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -88,14 +89,17 @@ public TResult MaxAll(Expression> field, /// The field to be maximized. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public Task MaxAllAsync(Field field, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MaxAllAsync(field: field, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -104,14 +108,17 @@ public Task MaxAllAsync(Field field, /// The field to be maximized. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public Task MaxAllAsync(Expression> field, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MaxAllAsync(field: field, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -121,14 +128,17 @@ public Task MaxAllAsync(Expression> field, /// The field to be maximized. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public Task MaxAllAsync(Field field, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MaxAllAsync(field: field, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -138,14 +148,17 @@ public Task MaxAllAsync(Field field, /// The field to be maximized. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public Task MaxAllAsync(Expression> field, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MaxAllAsync(field: field, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } #endregion diff --git a/RepoDb.Core/RepoDb/Operations/BaseRepository/Merge.cs b/RepoDb.Core/RepoDb/Operations/BaseRepository/Merge.cs index db68eb1ea..c8e610081 100644 --- a/RepoDb.Core/RepoDb/Operations/BaseRepository/Merge.cs +++ b/RepoDb.Core/RepoDb/Operations/BaseRepository/Merge.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Data; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -198,16 +199,19 @@ public TResult Merge(TEntity entity, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public Task MergeAsync(TEntity entity, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MergeAsync(entity: entity, fields: fields, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -218,18 +222,21 @@ public Task MergeAsync(TEntity entity, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public Task MergeAsync(TEntity entity, Field qualifier, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MergeAsync(entity: entity, qualifier: qualifier, fields: fields, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -240,18 +247,21 @@ public Task MergeAsync(TEntity entity, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public Task MergeAsync(TEntity entity, IEnumerable qualifiers, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MergeAsync(entity: entity, qualifiers: qualifiers, fields: fields, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -262,18 +272,21 @@ public Task MergeAsync(TEntity entity, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public Task MergeAsync(TEntity entity, Expression> qualifiers, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MergeAsync(entity: entity, qualifiers: qualifiers, fields: fields, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -284,16 +297,19 @@ public Task MergeAsync(TEntity entity, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public Task MergeAsync(TEntity entity, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MergeAsync(entity: entity, fields: fields, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -305,18 +321,21 @@ public Task MergeAsync(TEntity entity, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public Task MergeAsync(TEntity entity, Field qualifier, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MergeAsync(entity: entity, qualifier: qualifier, fields: fields, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -328,18 +347,21 @@ public Task MergeAsync(TEntity entity, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public Task MergeAsync(TEntity entity, IEnumerable qualifiers, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MergeAsync(entity: entity, qualifiers: qualifiers, fields: fields, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -351,18 +373,21 @@ public Task MergeAsync(TEntity entity, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public Task MergeAsync(TEntity entity, Expression> qualifiers, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MergeAsync(entity: entity, qualifiers: qualifiers, fields: fields, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } #endregion diff --git a/RepoDb.Core/RepoDb/Operations/BaseRepository/MergeAll.cs b/RepoDb.Core/RepoDb/Operations/BaseRepository/MergeAll.cs index 66731d555..47c8b229b 100644 --- a/RepoDb.Core/RepoDb/Operations/BaseRepository/MergeAll.cs +++ b/RepoDb.Core/RepoDb/Operations/BaseRepository/MergeAll.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Data; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -97,18 +98,21 @@ public int MergeAll(IEnumerable entities, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the merge process. public Task MergeAllAsync(IEnumerable entities, int batchSize = Constant.DefaultBatchOperationSize, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MergeAllAsync(entities: entities, batchSize: batchSize, fields: fields, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -120,20 +124,23 @@ public Task MergeAllAsync(IEnumerable entities, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the merge process. public Task MergeAllAsync(IEnumerable entities, IEnumerable qualifiers, int batchSize = Constant.DefaultBatchOperationSize, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MergeAllAsync(entities: entities, qualifiers: qualifiers, batchSize: batchSize, fields: fields, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -145,20 +152,23 @@ public Task MergeAllAsync(IEnumerable entities, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the merge process. public Task MergeAllAsync(IEnumerable entities, Expression> qualifiers, int batchSize = Constant.DefaultBatchOperationSize, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MergeAllAsync(entities: entities, qualifiers: qualifiers, batchSize: batchSize, fields: fields, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } #endregion diff --git a/RepoDb.Core/RepoDb/Operations/BaseRepository/Min.cs b/RepoDb.Core/RepoDb/Operations/BaseRepository/Min.cs index ab54fbb17..14c42ca04 100644 --- a/RepoDb.Core/RepoDb/Operations/BaseRepository/Min.cs +++ b/RepoDb.Core/RepoDb/Operations/BaseRepository/Min.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Data; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -404,16 +405,19 @@ public TResult Min(Expression> field, /// The dynamic expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public Task MinAsync(Field field, object where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MinAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -423,16 +427,19 @@ public Task MinAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public Task MinAsync(Field field, Expression> where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MinAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -442,16 +449,19 @@ public Task MinAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public Task MinAsync(Field field, QueryField where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MinAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -461,16 +471,19 @@ public Task MinAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public Task MinAsync(Field field, IEnumerable where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MinAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -480,16 +493,19 @@ public Task MinAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public Task MinAsync(Field field, QueryGroup where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MinAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -499,16 +515,19 @@ public Task MinAsync(Field field, /// The dynamic expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public Task MinAsync(Expression> field, object where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MinAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -518,16 +537,19 @@ public Task MinAsync(Expression> field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public Task MinAsync(Expression> field, Expression> where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MinAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -537,16 +559,19 @@ public Task MinAsync(Expression> field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public Task MinAsync(Expression> field, QueryField where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MinAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -556,16 +581,19 @@ public Task MinAsync(Expression> field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public Task MinAsync(Expression> field, IEnumerable where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MinAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -575,16 +603,19 @@ public Task MinAsync(Expression> field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public Task MinAsync(Expression> field, QueryGroup where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MinAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -594,16 +625,19 @@ public Task MinAsync(Expression> field, /// The dynamic expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public Task MinAsync(Field field, object where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MinAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -613,16 +647,19 @@ public Task MinAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public Task MinAsync(Field field, Expression> where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MinAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -632,16 +669,19 @@ public Task MinAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public Task MinAsync(Field field, QueryField where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MinAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -651,16 +691,19 @@ public Task MinAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public Task MinAsync(Field field, IEnumerable where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MinAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -670,16 +713,19 @@ public Task MinAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public Task MinAsync(Field field, QueryGroup where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MinAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -689,16 +735,19 @@ public Task MinAsync(Field field, /// The dynamic expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public Task MinAsync(Expression> field, object where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MinAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -708,16 +757,19 @@ public Task MinAsync(Expression> field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public Task MinAsync(Expression> field, Expression> where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MinAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -727,16 +779,19 @@ public Task MinAsync(Expression> field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public Task MinAsync(Expression> field, QueryField where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MinAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -746,16 +801,19 @@ public Task MinAsync(Expression> field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public Task MinAsync(Expression> field, IEnumerable where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MinAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -765,16 +823,19 @@ public Task MinAsync(Expression> field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public Task MinAsync(Expression> field, QueryGroup where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MinAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } #endregion diff --git a/RepoDb.Core/RepoDb/Operations/BaseRepository/MinAll.cs b/RepoDb.Core/RepoDb/Operations/BaseRepository/MinAll.cs index 6d710483d..e1ed63753 100644 --- a/RepoDb.Core/RepoDb/Operations/BaseRepository/MinAll.cs +++ b/RepoDb.Core/RepoDb/Operations/BaseRepository/MinAll.cs @@ -1,6 +1,7 @@ using System; using System.Data; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -88,14 +89,17 @@ public TResult MinAll(Expression> field, /// The field to be minimized. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public Task MinAllAsync(Field field, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MinAllAsync(field: field, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -104,14 +108,17 @@ public Task MinAllAsync(Field field, /// The field to be minimized. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public Task MinAllAsync(Expression> field, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MinAllAsync(field: field, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -121,14 +128,17 @@ public Task MinAllAsync(Expression> field, /// The field to be minimized. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public Task MinAllAsync(Field field, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MinAllAsync(field: field, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -138,14 +148,17 @@ public Task MinAllAsync(Field field, /// The field to be minimized. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public Task MinAllAsync(Expression> field, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.MinAllAsync(field: field, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } #endregion diff --git a/RepoDb.Core/RepoDb/Operations/BaseRepository/Query.cs b/RepoDb.Core/RepoDb/Operations/BaseRepository/Query.cs index 112d359e5..4ae761a90 100644 --- a/RepoDb.Core/RepoDb/Operations/BaseRepository/Query.cs +++ b/RepoDb.Core/RepoDb/Operations/BaseRepository/Query.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Data; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -410,6 +411,7 @@ public IEnumerable Query(QueryGroup where, /// The key to the cache item.By setting this argument, it will return the item from the cache if present, otherwise it will query the database. /// /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public Task> QueryAsync(string tableName, object what, @@ -418,7 +420,8 @@ public Task> QueryAsync(string tableName, int? top = 0, string hints = null, string cacheKey = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.QueryAsync(tableName: tableName, what: what, @@ -427,7 +430,8 @@ public Task> QueryAsync(string tableName, top: top, hints: hints, cacheKey: cacheKey, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -444,6 +448,7 @@ public Task> QueryAsync(string tableName, /// The key to the cache item.By setting this argument, it will return the item from the cache if present, otherwise it will query the database. /// /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public Task> QueryAsync(string tableName, TWhat what, @@ -452,7 +457,8 @@ public Task> QueryAsync(string tableName, int? top = 0, string hints = null, string cacheKey = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.QueryAsync(tableName: tableName, what: what, @@ -461,7 +467,8 @@ public Task> QueryAsync(string tableName, top: top, hints: hints, cacheKey: cacheKey, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -477,6 +484,7 @@ public Task> QueryAsync(string tableName, /// The key to the cache item.By setting this argument, it will return the item from the cache if present, otherwise it will query the database. /// /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public Task> QueryAsync(string tableName, Expression> where, @@ -485,7 +493,8 @@ public Task> QueryAsync(string tableName, int? top = 0, string hints = null, string cacheKey = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.QueryAsync(tableName: tableName, where: where, @@ -494,7 +503,8 @@ public Task> QueryAsync(string tableName, top: top, hints: hints, cacheKey: cacheKey, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -510,6 +520,7 @@ public Task> QueryAsync(string tableName, /// The key to the cache item.By setting this argument, it will return the item from the cache if present, otherwise it will query the database. /// /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public Task> QueryAsync(string tableName, QueryField where, @@ -518,7 +529,8 @@ public Task> QueryAsync(string tableName, int? top = 0, string hints = null, string cacheKey = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.QueryAsync(tableName: tableName, where: where, @@ -527,7 +539,8 @@ public Task> QueryAsync(string tableName, top: top, hints: hints, cacheKey: cacheKey, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -543,6 +556,7 @@ public Task> QueryAsync(string tableName, /// The key to the cache item.By setting this argument, it will return the item from the cache if present, otherwise it will query the database. /// /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public Task> QueryAsync(string tableName, IEnumerable where, @@ -551,7 +565,8 @@ public Task> QueryAsync(string tableName, int? top = 0, string hints = null, string cacheKey = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.QueryAsync(tableName: tableName, where: where, @@ -560,7 +575,8 @@ public Task> QueryAsync(string tableName, top: top, hints: hints, cacheKey: cacheKey, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -576,6 +592,7 @@ public Task> QueryAsync(string tableName, /// The key to the cache item.By setting this argument, it will return the item from the cache if present, otherwise it will query the database. /// /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public Task> QueryAsync(string tableName, QueryGroup where, @@ -584,7 +601,8 @@ public Task> QueryAsync(string tableName, int? top = 0, string hints = null, string cacheKey = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.QueryAsync(tableName: tableName, where: where, @@ -593,7 +611,8 @@ public Task> QueryAsync(string tableName, top: top, hints: hints, cacheKey: cacheKey, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -608,6 +627,7 @@ public Task> QueryAsync(string tableName, /// The key to the cache item.By setting this argument, it will return the item from the cache if present, otherwise it will query the database. /// /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public Task> QueryAsync(object what, IEnumerable fields = null, @@ -615,7 +635,8 @@ public Task> QueryAsync(object what, int? top = 0, string hints = null, string cacheKey = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.QueryAsync(what: what, fields: fields, @@ -623,7 +644,8 @@ public Task> QueryAsync(object what, top: top, hints: hints, cacheKey: cacheKey, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -639,6 +661,7 @@ public Task> QueryAsync(object what, /// The key to the cache item.By setting this argument, it will return the item from the cache if present, otherwise it will query the database. /// /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public Task> QueryAsync(TWhat what, IEnumerable fields = null, @@ -646,7 +669,8 @@ public Task> QueryAsync(TWhat what, int? top = 0, string hints = null, string cacheKey = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.QueryAsync(what: what, fields: fields, @@ -654,7 +678,8 @@ public Task> QueryAsync(TWhat what, top: top, hints: hints, cacheKey: cacheKey, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -669,6 +694,7 @@ public Task> QueryAsync(TWhat what, /// The key to the cache item.By setting this argument, it will return the item from the cache if present, otherwise it will query the database. /// /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public Task> QueryAsync(Expression> where, IEnumerable fields = null, @@ -676,7 +702,8 @@ public Task> QueryAsync(Expression> whe int? top = 0, string hints = null, string cacheKey = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.QueryAsync(where: where, fields: fields, @@ -684,7 +711,8 @@ public Task> QueryAsync(Expression> whe top: top, hints: hints, cacheKey: cacheKey, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -699,6 +727,7 @@ public Task> QueryAsync(Expression> whe /// The key to the cache item.By setting this argument, it will return the item from the cache if present, otherwise it will query the database. /// /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public Task> QueryAsync(QueryField where, IEnumerable fields = null, @@ -706,7 +735,8 @@ public Task> QueryAsync(QueryField where, int? top = 0, string hints = null, string cacheKey = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.QueryAsync(where: where, fields: fields, @@ -714,7 +744,8 @@ public Task> QueryAsync(QueryField where, top: top, hints: hints, cacheKey: cacheKey, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -729,6 +760,7 @@ public Task> QueryAsync(QueryField where, /// The key to the cache item.By setting this argument, it will return the item from the cache if present, otherwise it will query the database. /// /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public Task> QueryAsync(IEnumerable where, IEnumerable fields = null, @@ -736,7 +768,8 @@ public Task> QueryAsync(IEnumerable where, int? top = 0, string hints = null, string cacheKey = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.QueryAsync(where: where, fields: fields, @@ -744,7 +777,8 @@ public Task> QueryAsync(IEnumerable where, top: top, hints: hints, cacheKey: cacheKey, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -759,6 +793,7 @@ public Task> QueryAsync(IEnumerable where, /// The key to the cache item.By setting this argument, it will return the item from the cache if present, otherwise it will query the database. /// /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public Task> QueryAsync(QueryGroup where, IEnumerable fields = null, @@ -766,7 +801,8 @@ public Task> QueryAsync(QueryGroup where, int? top = 0, string hints = null, string cacheKey = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.QueryAsync(where: where, fields: fields, @@ -774,7 +810,8 @@ public Task> QueryAsync(QueryGroup where, top: top, hints: hints, cacheKey: cacheKey, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } #endregion diff --git a/RepoDb.Core/RepoDb/Operations/BaseRepository/QueryAll.cs b/RepoDb.Core/RepoDb/Operations/BaseRepository/QueryAll.cs index fe5a3ff48..578f02232 100644 --- a/RepoDb.Core/RepoDb/Operations/BaseRepository/QueryAll.cs +++ b/RepoDb.Core/RepoDb/Operations/BaseRepository/QueryAll.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Data; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -78,20 +79,23 @@ public IEnumerable QueryAll(IEnumerable fields = null, /// The key to the cache item.By setting this argument, it will return the item from the cache if present, otherwise it will query the database. /// /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public Task> QueryAllAsync(string tableName, IEnumerable fields = null, IEnumerable orderBy = null, string hints = null, string cacheKey = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.QueryAllAsync(tableName: tableName, fields: fields, orderBy: orderBy, hints: hints, cacheKey: cacheKey, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -104,18 +108,21 @@ public Task> QueryAllAsync(string tableName, /// The key to the cache item.By setting this argument, it will return the item from the cache if present, otherwise it will query the database. /// /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public Task> QueryAllAsync(IEnumerable fields = null, IEnumerable orderBy = null, string hints = null, string cacheKey = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.QueryAllAsync(fields: fields, orderBy: orderBy, hints: hints, cacheKey: cacheKey, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } #endregion diff --git a/RepoDb.Core/RepoDb/Operations/BaseRepository/Sum.cs b/RepoDb.Core/RepoDb/Operations/BaseRepository/Sum.cs index c1c668911..1cf8ca600 100644 --- a/RepoDb.Core/RepoDb/Operations/BaseRepository/Sum.cs +++ b/RepoDb.Core/RepoDb/Operations/BaseRepository/Sum.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Data; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -404,16 +405,19 @@ public TResult Sum(Expression> field, /// The dynamic expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public Task SumAsync(Field field, object where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.SumAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -423,16 +427,19 @@ public Task SumAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public Task SumAsync(Field field, Expression> where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.SumAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -442,16 +449,19 @@ public Task SumAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public Task SumAsync(Field field, QueryField where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.SumAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -461,16 +471,19 @@ public Task SumAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public Task SumAsync(Field field, IEnumerable where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.SumAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -480,16 +493,19 @@ public Task SumAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public Task SumAsync(Field field, QueryGroup where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.SumAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -499,16 +515,19 @@ public Task SumAsync(Field field, /// The dynamic expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public Task SumAsync(Expression> field, object where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.SumAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -518,16 +537,19 @@ public Task SumAsync(Expression> field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public Task SumAsync(Expression> field, Expression> where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.SumAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -537,16 +559,19 @@ public Task SumAsync(Expression> field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public Task SumAsync(Expression> field, QueryField where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.SumAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -556,16 +581,19 @@ public Task SumAsync(Expression> field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public Task SumAsync(Expression> field, IEnumerable where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.SumAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -575,16 +603,19 @@ public Task SumAsync(Expression> field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public Task SumAsync(Expression> field, QueryGroup where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.SumAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -594,16 +625,19 @@ public Task SumAsync(Expression> field, /// The dynamic expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public Task SumAsync(Field field, object where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.SumAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -613,16 +647,19 @@ public Task SumAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public Task SumAsync(Field field, Expression> where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.SumAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -632,16 +669,19 @@ public Task SumAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public Task SumAsync(Field field, QueryField where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.SumAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -651,16 +691,19 @@ public Task SumAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public Task SumAsync(Field field, IEnumerable where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.SumAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -670,16 +713,19 @@ public Task SumAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public Task SumAsync(Field field, QueryGroup where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.SumAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -689,16 +735,19 @@ public Task SumAsync(Field field, /// The dynamic expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public Task SumAsync(Expression> field, object where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.SumAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -708,16 +757,19 @@ public Task SumAsync(Expression> field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public Task SumAsync(Expression> field, Expression> where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.SumAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -727,16 +779,19 @@ public Task SumAsync(Expression> field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public Task SumAsync(Expression> field, QueryField where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.SumAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -746,16 +801,19 @@ public Task SumAsync(Expression> field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public Task SumAsync(Expression> field, IEnumerable where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.SumAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -765,16 +823,19 @@ public Task SumAsync(Expression> field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public Task SumAsync(Expression> field, QueryGroup where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.SumAsync(field: field, where: where, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } #endregion diff --git a/RepoDb.Core/RepoDb/Operations/BaseRepository/SumAll.cs b/RepoDb.Core/RepoDb/Operations/BaseRepository/SumAll.cs index 2fd2f8a3d..71bc9020e 100644 --- a/RepoDb.Core/RepoDb/Operations/BaseRepository/SumAll.cs +++ b/RepoDb.Core/RepoDb/Operations/BaseRepository/SumAll.cs @@ -1,6 +1,7 @@ using System; using System.Data; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -88,14 +89,17 @@ public TResult SumAll(Expression> field, /// The field to be summarized. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public Task SumAllAsync(Field field, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.SumAllAsync(field: field, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -104,14 +108,17 @@ public Task SumAllAsync(Field field, /// The field to be summarized. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public Task SumAllAsync(Expression> field, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.SumAllAsync(field: field, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -121,14 +128,17 @@ public Task SumAllAsync(Expression> field, /// The field to be summarized. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public Task SumAllAsync(Field field, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.SumAllAsync(field: field, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -138,14 +148,17 @@ public Task SumAllAsync(Field field, /// The field to be summarized. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public Task SumAllAsync(Expression> field, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.SumAllAsync(field: field, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } #endregion diff --git a/RepoDb.Core/RepoDb/Operations/BaseRepository/Truncate.cs b/RepoDb.Core/RepoDb/Operations/BaseRepository/Truncate.cs index 2d62159fe..c5fe8a407 100644 --- a/RepoDb.Core/RepoDb/Operations/BaseRepository/Truncate.cs +++ b/RepoDb.Core/RepoDb/Operations/BaseRepository/Truncate.cs @@ -1,5 +1,6 @@ using System; using System.Data; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -37,20 +38,24 @@ public int Truncate(IDbTransaction transaction = null) /// /// Truncates a table from the database in an asynchronous way. /// + /// The object to be used during the asynchronous operation. /// The number of rows affected. - public Task TruncateAsync() + public Task TruncateAsync(CancellationToken cancellationToken = default) { - return DbRepository.TruncateAsync(); + return DbRepository.TruncateAsync(cancellationToken: cancellationToken); } /// /// Truncates a table from the database in an asynchronous way. /// /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected. - public Task TruncateAsync(IDbTransaction transaction = null) + public Task TruncateAsync(IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { - return DbRepository.TruncateAsync(transaction: transaction); + return DbRepository.TruncateAsync(transaction: transaction, + cancellationToken: cancellationToken); } #endregion diff --git a/RepoDb.Core/RepoDb/Operations/BaseRepository/Update.cs b/RepoDb.Core/RepoDb/Operations/BaseRepository/Update.cs index e63882717..d5cc4c112 100644 --- a/RepoDb.Core/RepoDb/Operations/BaseRepository/Update.cs +++ b/RepoDb.Core/RepoDb/Operations/BaseRepository/Update.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Data; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -176,16 +177,19 @@ public int Update(TEntity entity, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public Task UpdateAsync(TEntity entity, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.UpdateAsync(entity: entity, fields: fields, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -197,18 +201,21 @@ public Task UpdateAsync(TEntity entity, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public Task UpdateAsync(TEntity entity, TWhat what, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.UpdateAsync(entity: entity, what: what, fields: fields, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -219,18 +226,21 @@ public Task UpdateAsync(TEntity entity, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public Task UpdateAsync(TEntity entity, object what, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.UpdateAsync(entity: entity, what: what, fields: fields, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -241,18 +251,21 @@ public Task UpdateAsync(TEntity entity, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public Task UpdateAsync(TEntity entity, Expression> where, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.UpdateAsync(entity: entity, where: where, fields: fields, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -263,18 +276,21 @@ public Task UpdateAsync(TEntity entity, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public Task UpdateAsync(TEntity entity, QueryField where, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.UpdateAsync(entity: entity, where: where, fields: fields, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -285,18 +301,21 @@ public Task UpdateAsync(TEntity entity, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public Task UpdateAsync(TEntity entity, IEnumerable where, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.UpdateAsync(entity: entity, where: where, fields: fields, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -307,18 +326,21 @@ public Task UpdateAsync(TEntity entity, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public Task UpdateAsync(TEntity entity, QueryGroup where, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.UpdateAsync(entity: entity, where: where, fields: fields, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } #endregion diff --git a/RepoDb.Core/RepoDb/Operations/BaseRepository/UpdateAll.cs b/RepoDb.Core/RepoDb/Operations/BaseRepository/UpdateAll.cs index 8cf6a8231..ac1709653 100644 --- a/RepoDb.Core/RepoDb/Operations/BaseRepository/UpdateAll.cs +++ b/RepoDb.Core/RepoDb/Operations/BaseRepository/UpdateAll.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Data; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -97,18 +98,21 @@ public int UpdateAll(IEnumerable entities, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public Task UpdateAllAsync(IEnumerable entities, int batchSize = Constant.DefaultBatchOperationSize, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.UpdateAllAsync(entities: entities, batchSize: batchSize, fields: fields, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -120,20 +124,23 @@ public Task UpdateAllAsync(IEnumerable entities, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public Task UpdateAllAsync(IEnumerable entities, IEnumerable qualifiers, int batchSize = Constant.DefaultBatchOperationSize, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.UpdateAllAsync(entities: entities, qualifiers: qualifiers, batchSize: batchSize, fields: fields, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -145,20 +152,23 @@ public Task UpdateAllAsync(IEnumerable entities, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public Task UpdateAllAsync(IEnumerable entities, Expression> qualifiers, int batchSize = Constant.DefaultBatchOperationSize, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { return DbRepository.UpdateAllAsync(entities: entities, qualifiers: qualifiers, batchSize: batchSize, fields: fields, hints: hints, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } #endregion diff --git a/RepoDb.Core/RepoDb/Operations/DbConnection/Average.cs b/RepoDb.Core/RepoDb/Operations/DbConnection/Average.cs index b23bdcc22..28ad6131a 100644 --- a/RepoDb.Core/RepoDb/Operations/DbConnection/Average.cs +++ b/RepoDb.Core/RepoDb/Operations/DbConnection/Average.cs @@ -7,6 +7,7 @@ using System.Data; using System.Linq; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -801,6 +802,7 @@ internal static TResult AverageInternal(this IDbConnection con /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public static Task AverageAsync(this IDbConnection connection, Field field, @@ -809,7 +811,8 @@ public static Task AverageAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return AverageAsyncInternal(connection: connection, @@ -819,7 +822,8 @@ public static Task AverageAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -834,6 +838,7 @@ public static Task AverageAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public static Task AverageAsync(this IDbConnection connection, Field field, @@ -842,7 +847,8 @@ public static Task AverageAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return AverageAsyncInternal(connection: connection, @@ -852,7 +858,8 @@ public static Task AverageAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -867,6 +874,7 @@ public static Task AverageAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public static Task AverageAsync(this IDbConnection connection, Field field, @@ -875,7 +883,8 @@ public static Task AverageAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return AverageAsyncInternal(connection: connection, @@ -885,7 +894,8 @@ public static Task AverageAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -900,6 +910,7 @@ public static Task AverageAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public static Task AverageAsync(this IDbConnection connection, Field field, @@ -908,7 +919,8 @@ public static Task AverageAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return AverageAsyncInternal(connection: connection, @@ -918,7 +930,8 @@ public static Task AverageAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -933,6 +946,7 @@ public static Task AverageAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public static Task AverageAsync(this IDbConnection connection, Field field, @@ -941,7 +955,8 @@ public static Task AverageAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return AverageAsyncInternal(connection: connection, @@ -951,7 +966,8 @@ public static Task AverageAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -966,6 +982,7 @@ public static Task AverageAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public static Task AverageAsync(this IDbConnection connection, Expression> field, @@ -974,7 +991,8 @@ public static Task AverageAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return AverageAsyncInternal(connection: connection, @@ -984,7 +1002,8 @@ public static Task AverageAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -999,6 +1018,7 @@ public static Task AverageAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public static Task AverageAsync(this IDbConnection connection, Expression> field, @@ -1007,7 +1027,8 @@ public static Task AverageAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return AverageAsyncInternal(connection: connection, @@ -1017,7 +1038,8 @@ public static Task AverageAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1032,6 +1054,7 @@ public static Task AverageAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public static Task AverageAsync(this IDbConnection connection, Expression> field, @@ -1040,7 +1063,8 @@ public static Task AverageAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return AverageAsyncInternal(connection: connection, @@ -1050,7 +1074,8 @@ public static Task AverageAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1065,6 +1090,7 @@ public static Task AverageAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public static Task AverageAsync(this IDbConnection connection, Expression> field, @@ -1073,7 +1099,8 @@ public static Task AverageAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return AverageAsyncInternal(connection: connection, @@ -1083,7 +1110,8 @@ public static Task AverageAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1098,6 +1126,7 @@ public static Task AverageAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public static Task AverageAsync(this IDbConnection connection, Expression> field, @@ -1106,7 +1135,8 @@ public static Task AverageAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return AverageAsyncInternal(connection: connection, @@ -1116,7 +1146,8 @@ public static Task AverageAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1131,6 +1162,7 @@ public static Task AverageAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. internal static Task AverageAsyncInternal(this IDbConnection connection, Field field, @@ -1139,7 +1171,8 @@ internal static Task AverageAsyncInternal(this IDbConnection co string hints = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { // Variables @@ -1164,7 +1197,8 @@ internal static Task AverageAsyncInternal(this IDbConnection co param: param, commandTimeout: commandTimeout, transaction: transaction, - trace: trace); + trace: trace, + cancellationToken: cancellationToken); } /// @@ -1180,6 +1214,7 @@ internal static Task AverageAsyncInternal(this IDbConnection co /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public static Task AverageAsync(this IDbConnection connection, Field field, @@ -1188,7 +1223,8 @@ public static Task AverageAsync(this IDbConnection co int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return AverageAsyncInternal(connection: connection, @@ -1198,7 +1234,8 @@ public static Task AverageAsync(this IDbConnection co commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1214,6 +1251,7 @@ public static Task AverageAsync(this IDbConnection co /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public static Task AverageAsync(this IDbConnection connection, Field field, @@ -1222,7 +1260,8 @@ public static Task AverageAsync(this IDbConnection co int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return AverageAsyncInternal(connection: connection, @@ -1232,7 +1271,8 @@ public static Task AverageAsync(this IDbConnection co commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1248,6 +1288,7 @@ public static Task AverageAsync(this IDbConnection co /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public static Task AverageAsync(this IDbConnection connection, Field field, @@ -1256,7 +1297,8 @@ public static Task AverageAsync(this IDbConnection co int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return AverageAsyncInternal(connection: connection, @@ -1266,7 +1308,8 @@ public static Task AverageAsync(this IDbConnection co commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1282,6 +1325,7 @@ public static Task AverageAsync(this IDbConnection co /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public static Task AverageAsync(this IDbConnection connection, Field field, @@ -1290,7 +1334,8 @@ public static Task AverageAsync(this IDbConnection co int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return AverageAsyncInternal(connection: connection, @@ -1300,7 +1345,8 @@ public static Task AverageAsync(this IDbConnection co commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1316,6 +1362,7 @@ public static Task AverageAsync(this IDbConnection co /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public static Task AverageAsync(this IDbConnection connection, Field field, @@ -1324,7 +1371,8 @@ public static Task AverageAsync(this IDbConnection co int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return AverageAsyncInternal(connection: connection, @@ -1334,7 +1382,8 @@ public static Task AverageAsync(this IDbConnection co commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1350,6 +1399,7 @@ public static Task AverageAsync(this IDbConnection co /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public static Task AverageAsync(this IDbConnection connection, Expression> field, @@ -1358,7 +1408,8 @@ public static Task AverageAsync(this IDbConnection co int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return AverageAsyncInternal(connection: connection, @@ -1368,7 +1419,8 @@ public static Task AverageAsync(this IDbConnection co commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1384,6 +1436,7 @@ public static Task AverageAsync(this IDbConnection co /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public static Task AverageAsync(this IDbConnection connection, Expression> field, @@ -1392,7 +1445,8 @@ public static Task AverageAsync(this IDbConnection co int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return AverageAsyncInternal(connection: connection, @@ -1402,7 +1456,8 @@ public static Task AverageAsync(this IDbConnection co commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1418,6 +1473,7 @@ public static Task AverageAsync(this IDbConnection co /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public static Task AverageAsync(this IDbConnection connection, Expression> field, @@ -1426,7 +1482,8 @@ public static Task AverageAsync(this IDbConnection co int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return AverageAsyncInternal(connection: connection, @@ -1436,7 +1493,8 @@ public static Task AverageAsync(this IDbConnection co commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1452,6 +1510,7 @@ public static Task AverageAsync(this IDbConnection co /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public static Task AverageAsync(this IDbConnection connection, Expression> field, @@ -1460,7 +1519,8 @@ public static Task AverageAsync(this IDbConnection co int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return AverageAsyncInternal(connection: connection, @@ -1470,7 +1530,8 @@ public static Task AverageAsync(this IDbConnection co commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1486,6 +1547,7 @@ public static Task AverageAsync(this IDbConnection co /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public static Task AverageAsync(this IDbConnection connection, Expression> field, @@ -1494,7 +1556,8 @@ public static Task AverageAsync(this IDbConnection co int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return AverageAsyncInternal(connection: connection, @@ -1504,7 +1567,8 @@ public static Task AverageAsync(this IDbConnection co commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1520,6 +1584,7 @@ public static Task AverageAsync(this IDbConnection co /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. internal static Task AverageAsyncInternal(this IDbConnection connection, Field field, @@ -1528,7 +1593,8 @@ internal static Task AverageAsyncInternal(this IDbCon string hints = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { // Variables @@ -1553,7 +1619,8 @@ internal static Task AverageAsyncInternal(this IDbCon param: param, commandTimeout: commandTimeout, transaction: transaction, - trace: trace); + trace: trace, + cancellationToken: cancellationToken); } #endregion @@ -1949,6 +2016,7 @@ internal static TResult AverageInternal(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public static Task AverageAsync(this IDbConnection connection, string tableName, @@ -1958,7 +2026,8 @@ public static Task AverageAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return AverageAsyncInternal(connection: connection, tableName: tableName, @@ -1968,7 +2037,8 @@ public static Task AverageAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1983,6 +2053,7 @@ public static Task AverageAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public static Task AverageAsync(this IDbConnection connection, string tableName, @@ -1992,7 +2063,8 @@ public static Task AverageAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return AverageAsyncInternal(connection: connection, tableName: tableName, @@ -2002,7 +2074,8 @@ public static Task AverageAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -2017,6 +2090,7 @@ public static Task AverageAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public static Task AverageAsync(this IDbConnection connection, string tableName, @@ -2026,7 +2100,8 @@ public static Task AverageAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return AverageAsyncInternal(connection: connection, tableName: tableName, @@ -2036,7 +2111,8 @@ public static Task AverageAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -2051,6 +2127,7 @@ public static Task AverageAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public static Task AverageAsync(this IDbConnection connection, string tableName, @@ -2060,7 +2137,8 @@ public static Task AverageAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return AverageAsyncInternal(connection: connection, tableName: tableName, @@ -2070,7 +2148,8 @@ public static Task AverageAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -2085,6 +2164,7 @@ public static Task AverageAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. internal static Task AverageAsyncInternal(this IDbConnection connection, string tableName, @@ -2094,7 +2174,8 @@ internal static Task AverageAsyncInternal(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { // Variables var request = new AverageRequest(tableName, @@ -2118,7 +2199,8 @@ internal static Task AverageAsyncInternal(this IDbConnection connection, param: param, commandTimeout: commandTimeout, transaction: transaction, - trace: trace); + trace: trace, + cancellationToken: cancellationToken); } /// @@ -2134,6 +2216,7 @@ internal static Task AverageAsyncInternal(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public static Task AverageAsync(this IDbConnection connection, string tableName, @@ -2143,7 +2226,8 @@ public static Task AverageAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return AverageAsyncInternal(connection: connection, tableName: tableName, @@ -2153,7 +2237,8 @@ public static Task AverageAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -2169,6 +2254,7 @@ public static Task AverageAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public static Task AverageAsync(this IDbConnection connection, string tableName, @@ -2178,7 +2264,8 @@ public static Task AverageAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return AverageAsyncInternal(connection: connection, tableName: tableName, @@ -2188,7 +2275,8 @@ public static Task AverageAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -2204,6 +2292,7 @@ public static Task AverageAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public static Task AverageAsync(this IDbConnection connection, string tableName, @@ -2213,7 +2302,8 @@ public static Task AverageAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return AverageAsyncInternal(connection: connection, tableName: tableName, @@ -2223,7 +2313,8 @@ public static Task AverageAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -2239,6 +2330,7 @@ public static Task AverageAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public static Task AverageAsync(this IDbConnection connection, string tableName, @@ -2248,7 +2340,8 @@ public static Task AverageAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return AverageAsyncInternal(connection: connection, tableName: tableName, @@ -2258,7 +2351,8 @@ public static Task AverageAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -2274,6 +2368,7 @@ public static Task AverageAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. internal static Task AverageAsyncInternal(this IDbConnection connection, string tableName, @@ -2283,7 +2378,8 @@ internal static Task AverageAsyncInternal(this IDbConnection c int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { // Variables var request = new AverageRequest(tableName, @@ -2307,7 +2403,8 @@ internal static Task AverageAsyncInternal(this IDbConnection c param: param, commandTimeout: commandTimeout, transaction: transaction, - trace: trace); + trace: trace, + cancellationToken: cancellationToken); } #endregion @@ -2392,13 +2489,15 @@ internal static TResult AverageInternalBase(this IDbConnection connecti /// The command timeout in seconds to be used. /// The transaction to be used. /// The trace object to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. internal static async Task AverageAsyncInternalBase(this IDbConnection connection, AverageRequest request, object param, int? commandTimeout = null, IDbTransaction transaction = null, - ITrace trace = null) + ITrace trace = null, + CancellationToken cancellationToken = default) { // Variables var commandType = CommandType.Text; @@ -2433,8 +2532,9 @@ internal static async Task AverageAsyncInternalBase(this IDbCo commandType: commandType, commandTimeout: commandTimeout, transaction: transaction, + cancellationToken: cancellationToken, entityType: request.Type, - dbFields: await DbFieldCache.GetAsync(connection, request.Name, transaction, true), + dbFields: await DbFieldCache.GetAsync(connection, request.Name, transaction, true, cancellationToken), skipCommandArrayParametersCheck: true); // After Execution diff --git a/RepoDb.Core/RepoDb/Operations/DbConnection/AverageAll.cs b/RepoDb.Core/RepoDb/Operations/DbConnection/AverageAll.cs index 58bdf0f25..d2161f11f 100644 --- a/RepoDb.Core/RepoDb/Operations/DbConnection/AverageAll.cs +++ b/RepoDb.Core/RepoDb/Operations/DbConnection/AverageAll.cs @@ -5,6 +5,7 @@ using System.Data; using System.Linq; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -193,6 +194,7 @@ internal static TResult AverageAllInternal(this IDbConnection /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public static Task AverageAllAsync(this IDbConnection connection, Field field, @@ -200,7 +202,8 @@ public static Task AverageAllAsync(this IDbConnection connectio int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return AverageAllAsyncInternal(connection: connection, @@ -209,7 +212,8 @@ public static Task AverageAllAsync(this IDbConnection connectio commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -223,6 +227,7 @@ public static Task AverageAllAsync(this IDbConnection connectio /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public static Task AverageAllAsync(this IDbConnection connection, Expression> field, @@ -230,7 +235,8 @@ public static Task AverageAllAsync(this IDbConnection connectio int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return AverageAllAsyncInternal(connection: connection, @@ -239,7 +245,8 @@ public static Task AverageAllAsync(this IDbConnection connectio commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -254,6 +261,7 @@ public static Task AverageAllAsync(this IDbConnection connectio /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public static Task AverageAllAsync(this IDbConnection connection, Field field, @@ -261,7 +269,8 @@ public static Task AverageAllAsync(this IDbConnection int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return AverageAllAsyncInternal(connection: connection, @@ -270,7 +279,8 @@ public static Task AverageAllAsync(this IDbConnection commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -285,6 +295,7 @@ public static Task AverageAllAsync(this IDbConnection /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public static Task AverageAllAsync(this IDbConnection connection, Expression> field, @@ -292,7 +303,8 @@ public static Task AverageAllAsync(this IDbConnection int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return AverageAllAsyncInternal(connection: connection, @@ -301,7 +313,8 @@ public static Task AverageAllAsync(this IDbConnection commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -316,6 +329,7 @@ public static Task AverageAllAsync(this IDbConnection /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. internal static Task AverageAllAsyncInternal(this IDbConnection connection, Field field, @@ -323,7 +337,8 @@ internal static Task AverageAllAsyncInternal(this IDb int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { // Variables @@ -341,7 +356,8 @@ internal static Task AverageAllAsyncInternal(this IDb param: param, commandTimeout: commandTimeout, transaction: transaction, - trace: trace); + trace: trace, + cancellationToken: cancellationToken); } #endregion @@ -465,6 +481,7 @@ internal static TResult AverageAllInternal(this IDbConnection connectio /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public static Task AverageAllAsync(this IDbConnection connection, string tableName, @@ -473,7 +490,8 @@ public static Task AverageAllAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return AverageAllAsyncInternal(connection: connection, tableName: tableName, @@ -482,7 +500,8 @@ public static Task AverageAllAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -497,6 +516,7 @@ public static Task AverageAllAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public static Task AverageAllAsync(this IDbConnection connection, string tableName, @@ -505,7 +525,8 @@ public static Task AverageAllAsync(this IDbConnection connecti int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return AverageAllAsyncInternal(connection: connection, tableName: tableName, @@ -514,7 +535,8 @@ public static Task AverageAllAsync(this IDbConnection connecti commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -529,6 +551,7 @@ public static Task AverageAllAsync(this IDbConnection connecti /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. internal static Task AverageAllAsyncInternal(this IDbConnection connection, string tableName, @@ -537,7 +560,8 @@ internal static Task AverageAllAsyncInternal(this IDbConnectio int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { // Variables var request = new AverageAllRequest(tableName, @@ -553,7 +577,8 @@ internal static Task AverageAllAsyncInternal(this IDbConnectio param: null, commandTimeout: commandTimeout, transaction: transaction, - trace: trace); + trace: trace, + cancellationToken: cancellationToken); } #endregion @@ -640,13 +665,15 @@ internal static TResult AverageAllInternalBase(this IDbConnection conne /// The command timeout in seconds to be used. /// The transaction to be used. /// The trace object to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. internal static async Task AverageAllAsyncInternalBase(this IDbConnection connection, AverageAllRequest request, object param, int? commandTimeout = null, IDbTransaction transaction = null, - ITrace trace = null) + ITrace trace = null, + CancellationToken cancellationToken = default) { // Variables var commandType = CommandType.Text; @@ -681,8 +708,9 @@ internal static async Task AverageAllAsyncInternalBase(this ID commandType: commandType, commandTimeout: commandTimeout, transaction: transaction, + cancellationToken: cancellationToken, entityType: request.Type, - dbFields: await DbFieldCache.GetAsync(connection, request.Name, transaction, true), + dbFields: await DbFieldCache.GetAsync(connection, request.Name, transaction, true, cancellationToken), skipCommandArrayParametersCheck: true); // After Execution diff --git a/RepoDb.Core/RepoDb/Operations/DbConnection/BatchQuery.cs b/RepoDb.Core/RepoDb/Operations/DbConnection/BatchQuery.cs index d8e3a447f..8431ea47d 100644 --- a/RepoDb.Core/RepoDb/Operations/DbConnection/BatchQuery.cs +++ b/RepoDb.Core/RepoDb/Operations/DbConnection/BatchQuery.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Data; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -610,6 +611,7 @@ internal static IEnumerable BatchQueryInternal(this IDbConnect /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public static Task> BatchQueryAsync(this IDbConnection connection, string tableName, @@ -621,7 +623,8 @@ public static Task> BatchQueryAsync(this IDbConnec int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return BatchQueryAsyncInternal(connection, @@ -635,7 +638,8 @@ public static Task> BatchQueryAsync(this IDbConnec commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -654,6 +658,7 @@ public static Task> BatchQueryAsync(this IDbConnec /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public static Task> BatchQueryAsync(this IDbConnection connection, string tableName, @@ -666,7 +671,8 @@ public static Task> BatchQueryAsync(this IDbConnec int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return BatchQueryAsyncInternal(connection: connection, @@ -680,7 +686,8 @@ public static Task> BatchQueryAsync(this IDbConnec commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -699,6 +706,7 @@ public static Task> BatchQueryAsync(this IDbConnec /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public static Task> BatchQueryAsync(this IDbConnection connection, string tableName, @@ -711,7 +719,8 @@ public static Task> BatchQueryAsync(this IDbConnec int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return BatchQueryAsyncInternal(connection: connection, @@ -725,7 +734,8 @@ public static Task> BatchQueryAsync(this IDbConnec commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -744,6 +754,7 @@ public static Task> BatchQueryAsync(this IDbConnec /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public static Task> BatchQueryAsync(this IDbConnection connection, string tableName, @@ -756,7 +767,8 @@ public static Task> BatchQueryAsync(this IDbConnec int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return BatchQueryAsyncInternal(connection: connection, @@ -770,7 +782,8 @@ public static Task> BatchQueryAsync(this IDbConnec commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -789,6 +802,7 @@ public static Task> BatchQueryAsync(this IDbConnec /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public static Task> BatchQueryAsync(this IDbConnection connection, string tableName, @@ -801,7 +815,8 @@ public static Task> BatchQueryAsync(this IDbConnec int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return BatchQueryAsyncInternal(connection: connection, @@ -815,7 +830,8 @@ public static Task> BatchQueryAsync(this IDbConnec commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -834,6 +850,7 @@ public static Task> BatchQueryAsync(this IDbConnec /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public static Task> BatchQueryAsync(this IDbConnection connection, string tableName, @@ -846,7 +863,8 @@ public static Task> BatchQueryAsync(this IDbConnec int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return BatchQueryAsyncInternal(connection: connection, @@ -860,7 +878,8 @@ public static Task> BatchQueryAsync(this IDbConnec commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -877,6 +896,7 @@ public static Task> BatchQueryAsync(this IDbConnec /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public static Task> BatchQueryAsync(this IDbConnection connection, int page, @@ -887,7 +907,8 @@ public static Task> BatchQueryAsync(this IDbConnec int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return BatchQueryAsyncInternal(connection, @@ -901,7 +922,8 @@ public static Task> BatchQueryAsync(this IDbConnec commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -919,6 +941,7 @@ public static Task> BatchQueryAsync(this IDbConnec /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public static Task> BatchQueryAsync(this IDbConnection connection, int page, @@ -930,7 +953,8 @@ public static Task> BatchQueryAsync(this IDbConnec int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return BatchQueryAsyncInternal(connection: connection, @@ -944,7 +968,8 @@ public static Task> BatchQueryAsync(this IDbConnec commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -962,6 +987,7 @@ public static Task> BatchQueryAsync(this IDbConnec /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public static Task> BatchQueryAsync(this IDbConnection connection, int page, @@ -973,7 +999,8 @@ public static Task> BatchQueryAsync(this IDbConnec int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return BatchQueryAsyncInternal(connection: connection, @@ -987,7 +1014,8 @@ public static Task> BatchQueryAsync(this IDbConnec commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1005,6 +1033,7 @@ public static Task> BatchQueryAsync(this IDbConnec /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public static Task> BatchQueryAsync(this IDbConnection connection, int page, @@ -1016,7 +1045,8 @@ public static Task> BatchQueryAsync(this IDbConnec int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return BatchQueryAsyncInternal(connection: connection, @@ -1030,7 +1060,8 @@ public static Task> BatchQueryAsync(this IDbConnec commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1048,6 +1079,7 @@ public static Task> BatchQueryAsync(this IDbConnec /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public static Task> BatchQueryAsync(this IDbConnection connection, int page, @@ -1059,7 +1091,8 @@ public static Task> BatchQueryAsync(this IDbConnec int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return BatchQueryAsyncInternal(connection: connection, @@ -1073,7 +1106,8 @@ public static Task> BatchQueryAsync(this IDbConnec commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1091,6 +1125,7 @@ public static Task> BatchQueryAsync(this IDbConnec /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public static Task> BatchQueryAsync(this IDbConnection connection, int page, @@ -1102,7 +1137,8 @@ public static Task> BatchQueryAsync(this IDbConnec int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return BatchQueryAsyncInternal(connection: connection, @@ -1116,7 +1152,8 @@ public static Task> BatchQueryAsync(this IDbConnec commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1135,6 +1172,7 @@ public static Task> BatchQueryAsync(this IDbConnec /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. internal static async Task> BatchQueryAsyncInternal(this IDbConnection connection, string tableName, @@ -1147,12 +1185,13 @@ internal static async Task> BatchQueryAsyncInternal(fields) ?? - (await DbFieldCache.GetAsync(connection, tableName, transaction))?.AsFields(); + (await DbFieldCache.GetAsync(connection, tableName, transaction, true, cancellationToken))?.AsFields(); // Return return await BatchQueryAsyncInternalBase(connection: connection, @@ -1166,7 +1205,8 @@ internal static async Task> BatchQueryAsyncInternal BatchQuery(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of dynamic objects. public static Task> BatchQueryAsync(this IDbConnection connection, string tableName, @@ -1415,7 +1456,8 @@ public static Task> BatchQueryAsync(this IDbConnection conn int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return BatchQueryAsyncInternal(connection, tableName: tableName, @@ -1428,7 +1470,8 @@ public static Task> BatchQueryAsync(this IDbConnection conn commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1446,6 +1489,7 @@ public static Task> BatchQueryAsync(this IDbConnection conn /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of dynamic objects. public static Task> BatchQueryAsync(this IDbConnection connection, string tableName, @@ -1458,7 +1502,8 @@ public static Task> BatchQueryAsync(this IDbConnection conn int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return BatchQueryAsyncInternal(connection: connection, tableName: tableName, @@ -1471,7 +1516,8 @@ public static Task> BatchQueryAsync(this IDbConnection conn commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1489,6 +1535,7 @@ public static Task> BatchQueryAsync(this IDbConnection conn /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of dynamic objects. public static Task> BatchQueryAsync(this IDbConnection connection, string tableName, @@ -1501,7 +1548,8 @@ public static Task> BatchQueryAsync(this IDbConnection conn int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return BatchQueryAsyncInternal(connection: connection, tableName: tableName, @@ -1514,7 +1562,8 @@ public static Task> BatchQueryAsync(this IDbConnection conn commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1532,6 +1581,7 @@ public static Task> BatchQueryAsync(this IDbConnection conn /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of dynamic objects. public static Task> BatchQueryAsync(this IDbConnection connection, string tableName, @@ -1544,7 +1594,8 @@ public static Task> BatchQueryAsync(this IDbConnection conn int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return BatchQueryAsyncInternal(connection: connection, tableName: tableName, @@ -1557,7 +1608,8 @@ public static Task> BatchQueryAsync(this IDbConnection conn commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1575,6 +1627,7 @@ public static Task> BatchQueryAsync(this IDbConnection conn /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of dynamic objects. public static Task> BatchQueryAsync(this IDbConnection connection, string tableName, @@ -1587,7 +1640,8 @@ public static Task> BatchQueryAsync(this IDbConnection conn int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return BatchQueryAsyncInternal(connection: connection, tableName: tableName, @@ -1600,7 +1654,8 @@ public static Task> BatchQueryAsync(this IDbConnection conn commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } #endregion @@ -1725,6 +1780,7 @@ internal static IEnumerable BatchQueryInternalBase(this IDbCon /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. internal static async Task> BatchQueryAsyncInternalBase(this IDbConnection connection, string tableName, @@ -1737,7 +1793,8 @@ internal static async Task> BatchQueryAsyncInternalBase> BatchQueryAsyncInternalBase(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An integer value that holds the number of rows from the table. public static Task CountAsync(this IDbConnection connection, object where = null, @@ -234,7 +236,8 @@ public static Task CountAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return CountAsyncInternal(connection: connection, @@ -243,7 +246,8 @@ public static Task CountAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -257,6 +261,7 @@ public static Task CountAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An integer value that holds the number of rows from the table. public static Task CountAsync(this IDbConnection connection, Expression> where = null, @@ -264,7 +269,8 @@ public static Task CountAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return CountAsyncInternal(connection: connection, @@ -273,7 +279,8 @@ public static Task CountAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -287,6 +294,7 @@ public static Task CountAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An integer value that holds the number of rows from the table. public static Task CountAsync(this IDbConnection connection, QueryField where = null, @@ -294,7 +302,8 @@ public static Task CountAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return CountAsyncInternal(connection: connection, @@ -303,7 +312,8 @@ public static Task CountAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -317,6 +327,7 @@ public static Task CountAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An integer value that holds the number of rows from the table. public static Task CountAsync(this IDbConnection connection, IEnumerable where = null, @@ -324,7 +335,8 @@ public static Task CountAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return CountAsyncInternal(connection: connection, @@ -333,7 +345,8 @@ public static Task CountAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -347,6 +360,7 @@ public static Task CountAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An integer value that holds the number of rows from the table. public static Task CountAsync(this IDbConnection connection, QueryGroup where = null, @@ -354,7 +368,8 @@ public static Task CountAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return CountAsyncInternal(connection: connection, @@ -363,7 +378,8 @@ public static Task CountAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -377,6 +393,7 @@ public static Task CountAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An integer value that holds the number of rows from the table. internal static Task CountAsyncInternal(this IDbConnection connection, QueryGroup where = null, @@ -384,7 +401,8 @@ internal static Task CountAsyncInternal(this IDbConnection connec string hints = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { // Variables @@ -408,7 +426,8 @@ internal static Task CountAsyncInternal(this IDbConnection connec param: param, commandTimeout: commandTimeout, transaction: transaction, - trace: trace); + trace: trace, + cancellationToken: cancellationToken); } #endregion @@ -599,6 +618,7 @@ internal static long CountInternal(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An integer value that holds the number of rows from the table. public static Task CountAsync(this IDbConnection connection, string tableName, @@ -607,7 +627,8 @@ public static Task CountAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return CountAsyncInternal(connection: connection, tableName: tableName, @@ -616,7 +637,8 @@ public static Task CountAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -630,6 +652,7 @@ public static Task CountAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An integer value that holds the number of rows from the table. public static Task CountAsync(this IDbConnection connection, string tableName, @@ -638,7 +661,8 @@ public static Task CountAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return CountAsyncInternal(connection: connection, tableName: tableName, @@ -647,7 +671,8 @@ public static Task CountAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -661,6 +686,7 @@ public static Task CountAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An integer value that holds the number of rows from the table. public static Task CountAsync(this IDbConnection connection, string tableName, @@ -669,7 +695,8 @@ public static Task CountAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return CountAsyncInternal(connection: connection, tableName: tableName, @@ -678,7 +705,8 @@ public static Task CountAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -692,6 +720,7 @@ public static Task CountAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An integer value that holds the number of rows from the table. public static Task CountAsync(this IDbConnection connection, string tableName, @@ -700,7 +729,8 @@ public static Task CountAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return CountAsyncInternal(connection: connection, tableName: tableName, @@ -709,7 +739,8 @@ public static Task CountAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -723,6 +754,7 @@ public static Task CountAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An integer value that holds the number of rows from the table. internal static Task CountAsyncInternal(this IDbConnection connection, string tableName, @@ -731,7 +763,8 @@ internal static Task CountAsyncInternal(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { // Variables var request = new CountRequest(tableName, @@ -754,7 +787,8 @@ internal static Task CountAsyncInternal(this IDbConnection connection, param: param, commandTimeout: commandTimeout, transaction: transaction, - trace: trace); + trace: trace, + cancellationToken: cancellationToken); } #endregion @@ -839,13 +873,15 @@ internal static long CountInternalBase(this IDbConnection connection, /// The command timeout in seconds to be used. /// The transaction to be used. /// The trace object to be used. + /// The object to be used during the asynchronous operation. /// An integer value that holds the number of rows from the table. internal static async Task CountAsyncInternalBase(this IDbConnection connection, CountRequest request, object param, int? commandTimeout = null, IDbTransaction transaction = null, - ITrace trace = null) + ITrace trace = null, + CancellationToken cancellationToken = default) { // Variables var commandType = CommandType.Text; @@ -880,8 +916,9 @@ internal static async Task CountAsyncInternalBase(this IDbConnection conne commandType: commandType, commandTimeout: commandTimeout, transaction: transaction, + cancellationToken: cancellationToken, entityType: request.Type, - dbFields: await DbFieldCache.GetAsync(connection, request.Name, transaction, true), + dbFields: await DbFieldCache.GetAsync(connection, request.Name, transaction, true, cancellationToken), skipCommandArrayParametersCheck: true); // After Execution diff --git a/RepoDb.Core/RepoDb/Operations/DbConnection/CountAll.cs b/RepoDb.Core/RepoDb/Operations/DbConnection/CountAll.cs index d9a0768ed..aa60c6aee 100644 --- a/RepoDb.Core/RepoDb/Operations/DbConnection/CountAll.cs +++ b/RepoDb.Core/RepoDb/Operations/DbConnection/CountAll.cs @@ -3,6 +3,7 @@ using RepoDb.Requests; using System; using System.Data; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -91,13 +92,15 @@ internal static long CountAllInternal(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An integer value that holds the number of rows from the table. public static Task CountAllAsync(this IDbConnection connection, string hints = null, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return CountAllAsyncInternal(connection: connection, @@ -105,7 +108,8 @@ public static Task CountAllAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -118,13 +122,15 @@ public static Task CountAllAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An integer value that holds the number of rows from the table. internal static Task CountAllAsyncInternal(this IDbConnection connection, string hints = null, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { // Variables @@ -141,7 +147,8 @@ internal static Task CountAllAsyncInternal(this IDbConnection con param: param, commandTimeout: commandTimeout, transaction: transaction, - trace: trace); + trace: trace, + cancellationToken: cancellationToken); } #endregion @@ -226,6 +233,7 @@ internal static long CountAllInternal(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An integer value that holds the number of rows from the table. public static Task CountAllAsync(this IDbConnection connection, string tableName, @@ -233,7 +241,8 @@ public static Task CountAllAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return CountAllAsyncInternal(connection: connection, tableName: tableName, @@ -241,7 +250,8 @@ public static Task CountAllAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -254,6 +264,7 @@ public static Task CountAllAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An integer value that holds the number of rows from the table. internal static Task CountAllAsyncInternal(this IDbConnection connection, string tableName, @@ -261,7 +272,8 @@ internal static Task CountAllAsyncInternal(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { // Variables var request = new CountAllRequest(tableName, @@ -277,7 +289,8 @@ internal static Task CountAllAsyncInternal(this IDbConnection connection, param: param, commandTimeout: commandTimeout, transaction: transaction, - trace: trace); + trace: trace, + cancellationToken: cancellationToken); } #endregion @@ -362,13 +375,15 @@ internal static long CountAllInternalBase(this IDbConnection connection, /// The command timeout in seconds to be used. /// The transaction to be used. /// The trace object to be used. + /// The object to be used during the asynchronous operation. /// An integer value that holds the number of rows from the table. internal static async Task CountAllAsyncInternalBase(this IDbConnection connection, CountAllRequest request, object param, int? commandTimeout = null, IDbTransaction transaction = null, - ITrace trace = null) + ITrace trace = null, + CancellationToken cancellationToken = default) { // Variables var commandType = CommandType.Text; @@ -403,8 +418,9 @@ internal static async Task CountAllAsyncInternalBase(this IDbConnection co commandType: commandType, commandTimeout: commandTimeout, transaction: transaction, + cancellationToken: cancellationToken, entityType: request.Type, - dbFields: await DbFieldCache.GetAsync(connection, request.Name, transaction, true), + dbFields: await DbFieldCache.GetAsync(connection, request.Name, transaction, true, cancellationToken), skipCommandArrayParametersCheck: true); // After Execution diff --git a/RepoDb.Core/RepoDb/Operations/DbConnection/Delete.cs b/RepoDb.Core/RepoDb/Operations/DbConnection/Delete.cs index ce9cf4786..f265e10f5 100644 --- a/RepoDb.Core/RepoDb/Operations/DbConnection/Delete.cs +++ b/RepoDb.Core/RepoDb/Operations/DbConnection/Delete.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Data; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -289,6 +290,7 @@ internal static int DeleteInternal(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. public static async Task DeleteAsync(this IDbConnection connection, TEntity entity, @@ -296,17 +298,19 @@ public static async Task DeleteAsync(this IDbConnection connection int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { - var key = await GetAndGuardPrimaryKeyOrIdentityKeyAsync(connection, transaction); + var key = await GetAndGuardPrimaryKeyOrIdentityKeyAsync(connection, transaction, cancellationToken); return await DeleteAsyncInternal(connection: connection, where: ToQueryGroup(key, entity), hints: hints, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -321,6 +325,7 @@ public static async Task DeleteAsync(this IDbConnection connection /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. public static async Task DeleteAsync(this IDbConnection connection, TWhat what, @@ -328,16 +333,18 @@ public static async Task DeleteAsync(this IDbConnection con int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return await DeleteAsyncInternal(connection: connection, - where: await WhatToQueryGroupAsync(connection, what, transaction), + where: await WhatToQueryGroupAsync(connection, what, transaction, cancellationToken), hints: hints, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -351,6 +358,7 @@ public static async Task DeleteAsync(this IDbConnection con /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. public static async Task DeleteAsync(this IDbConnection connection, object what, @@ -358,16 +366,18 @@ public static async Task DeleteAsync(this IDbConnection connection int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return await DeleteAsyncInternal(connection: connection, - where: await WhatToQueryGroupAsync(connection, what, transaction), + where: await WhatToQueryGroupAsync(connection, what, transaction, cancellationToken), hints: hints, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -381,6 +391,7 @@ public static async Task DeleteAsync(this IDbConnection connection /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. public static Task DeleteAsync(this IDbConnection connection, Expression> where, @@ -388,7 +399,8 @@ public static Task DeleteAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return DeleteAsyncInternal(connection: connection, @@ -397,7 +409,8 @@ public static Task DeleteAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -411,6 +424,7 @@ public static Task DeleteAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. public static Task DeleteAsync(this IDbConnection connection, QueryField where, @@ -418,7 +432,8 @@ public static Task DeleteAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return DeleteAsyncInternal(connection: connection, @@ -427,7 +442,8 @@ public static Task DeleteAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -441,6 +457,7 @@ public static Task DeleteAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. public static Task DeleteAsync(this IDbConnection connection, IEnumerable where, @@ -448,7 +465,8 @@ public static Task DeleteAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return DeleteAsyncInternal(connection: connection, @@ -457,7 +475,8 @@ public static Task DeleteAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -471,6 +490,7 @@ public static Task DeleteAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. public static Task DeleteAsync(this IDbConnection connection, QueryGroup where, @@ -478,7 +498,8 @@ public static Task DeleteAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return DeleteAsyncInternal(connection: connection, @@ -487,7 +508,8 @@ public static Task DeleteAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -501,6 +523,7 @@ public static Task DeleteAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. internal static Task DeleteAsyncInternal(this IDbConnection connection, QueryGroup where, @@ -508,7 +531,8 @@ internal static Task DeleteAsyncInternal(this IDbConnection connec int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { // Variables @@ -532,7 +556,8 @@ internal static Task DeleteAsyncInternal(this IDbConnection connec param: param, commandTimeout: commandTimeout, transaction: transaction, - trace: trace); + trace: trace, + cancellationToken: cancellationToken); } #endregion @@ -756,6 +781,7 @@ internal static int DeleteInternal(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. public static async Task DeleteAsync(this IDbConnection connection, string tableName, @@ -764,16 +790,18 @@ public static async Task DeleteAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return await DeleteAsyncInternal(connection: connection, tableName: tableName, - where: await WhatToQueryGroupAsync(connection, tableName, what, transaction), + where: await WhatToQueryGroupAsync(connection, tableName, what, transaction, cancellationToken), hints: hints, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -787,6 +815,7 @@ public static async Task DeleteAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. public static async Task DeleteAsync(this IDbConnection connection, string tableName, @@ -795,16 +824,18 @@ public static async Task DeleteAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return await DeleteAsyncInternal(connection: connection, tableName: tableName, - where: await WhatToQueryGroupAsync(connection, tableName, what, transaction), + where: await WhatToQueryGroupAsync(connection, tableName, what, transaction, cancellationToken), hints: hints, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -818,6 +849,7 @@ public static async Task DeleteAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. public static Task DeleteAsync(this IDbConnection connection, string tableName, @@ -826,7 +858,8 @@ public static Task DeleteAsync(this IDbConnection connection, string hints = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return DeleteAsyncInternal(connection: connection, tableName: tableName, @@ -835,7 +868,8 @@ public static Task DeleteAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -849,6 +883,7 @@ public static Task DeleteAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. public static Task DeleteAsync(this IDbConnection connection, string tableName, @@ -857,7 +892,8 @@ public static Task DeleteAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return DeleteAsyncInternal(connection: connection, tableName: tableName, @@ -866,7 +902,8 @@ public static Task DeleteAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -880,6 +917,7 @@ public static Task DeleteAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. public static Task DeleteAsync(this IDbConnection connection, string tableName, @@ -888,7 +926,8 @@ public static Task DeleteAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return DeleteAsyncInternal(connection: connection, tableName: tableName, @@ -897,7 +936,8 @@ public static Task DeleteAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -911,6 +951,7 @@ public static Task DeleteAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. internal static Task DeleteAsyncInternal(this IDbConnection connection, string tableName, @@ -919,7 +960,8 @@ internal static Task DeleteAsyncInternal(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { // Variables var request = new DeleteRequest(tableName, @@ -942,7 +984,8 @@ internal static Task DeleteAsyncInternal(this IDbConnection connection, param: param, commandTimeout: commandTimeout, transaction: transaction, - trace: trace); + trace: trace, + cancellationToken: cancellationToken); } #endregion @@ -1027,13 +1070,15 @@ internal static int DeleteInternalBase(this IDbConnection connection, /// The command timeout in seconds to be used. /// The transaction to be used. /// The trace object to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. internal static async Task DeleteAsyncInternalBase(this IDbConnection connection, DeleteRequest request, object param, int? commandTimeout = null, IDbTransaction transaction = null, - ITrace trace = null) + ITrace trace = null, + CancellationToken cancellationToken = default) { // Variables var commandType = CommandType.Text; @@ -1068,8 +1113,9 @@ internal static async Task DeleteAsyncInternalBase(this IDbConnection conne commandType: commandType, commandTimeout: commandTimeout, transaction: transaction, + cancellationToken: cancellationToken, entityType: request.Type, - dbFields: await DbFieldCache.GetAsync(connection, request.Name, transaction, true), + dbFields: await DbFieldCache.GetAsync(connection, request.Name, transaction, true, cancellationToken), skipCommandArrayParametersCheck: true); // After Execution diff --git a/RepoDb.Core/RepoDb/Operations/DbConnection/DeleteAll.cs b/RepoDb.Core/RepoDb/Operations/DbConnection/DeleteAll.cs index 165d0d2d5..f10b9dd99 100644 --- a/RepoDb.Core/RepoDb/Operations/DbConnection/DeleteAll.cs +++ b/RepoDb.Core/RepoDb/Operations/DbConnection/DeleteAll.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.Data; using System.Linq; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -303,6 +304,7 @@ internal static int DeleteAllInternal(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. public static async Task DeleteAllAsync(this IDbConnection connection, string tableName, @@ -311,10 +313,11 @@ public static async Task DeleteAllAsync(this IDbConnection connect int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { - var key = await GetAndGuardPrimaryKeyOrIdentityKeyAsync(connection, transaction); + var key = await GetAndGuardPrimaryKeyOrIdentityKeyAsync(connection, transaction, cancellationToken); var keys = ExtractPropertyValues(entities, key).AsList(); return await DeleteAllAsyncInternal(connection: connection, @@ -324,7 +327,8 @@ public static async Task DeleteAllAsync(this IDbConnection connect commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -340,6 +344,7 @@ public static async Task DeleteAllAsync(this IDbConnection connect /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. public static async Task DeleteAllAsync(this IDbConnection connection, string tableName, @@ -348,7 +353,8 @@ public static async Task DeleteAllAsync(this IDbConnection c int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return await DeleteAllAsyncInternal(connection: connection, @@ -358,7 +364,8 @@ public static async Task DeleteAllAsync(this IDbConnection c commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -373,6 +380,7 @@ public static async Task DeleteAllAsync(this IDbConnection c /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. public static async Task DeleteAllAsync(this IDbConnection connection, string tableName, @@ -381,7 +389,8 @@ public static async Task DeleteAllAsync(this IDbConnection connect int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return await DeleteAllAsyncInternal(connection: connection, @@ -391,11 +400,12 @@ public static async Task DeleteAllAsync(this IDbConnection connect commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// - /// Delete all the rows from the table in an asynchronous way. It uses the operation as the underlying operation. + /// Delete all the rows from the table in an asynchronous way. /// /// The type of the data entity. /// The connection object to be used. @@ -405,6 +415,7 @@ public static async Task DeleteAllAsync(this IDbConnection connect /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. public static async Task DeleteAllAsync(this IDbConnection connection, IEnumerable entities, @@ -412,10 +423,11 @@ public static async Task DeleteAllAsync(this IDbConnection connect int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { - var key = await GetAndGuardPrimaryKeyOrIdentityKeyAsync(connection, transaction); + var key = await GetAndGuardPrimaryKeyOrIdentityKeyAsync(connection, transaction, cancellationToken); var keys = ExtractPropertyValues(entities, key)?.AsList(); return await DeleteAllAsyncInternal(connection: connection, @@ -425,11 +437,12 @@ public static async Task DeleteAllAsync(this IDbConnection connect commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// - /// Delete all the rows from the table in an asynchronous way. It uses the operation as the underlying operation. + /// Delete all the rows from the table in an asynchronous way. /// /// The type of the data entity. /// The type of the key column. @@ -440,6 +453,7 @@ public static async Task DeleteAllAsync(this IDbConnection connect /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. public static Task DeleteAllAsync(this IDbConnection connection, IEnumerable keys, @@ -447,7 +461,8 @@ public static Task DeleteAllAsync(this IDbConnection connect int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return DeleteAllAsyncInternal(connection: connection, @@ -457,11 +472,12 @@ public static Task DeleteAllAsync(this IDbConnection connect commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// - /// Delete all the rows from the table in an asynchronous way. It uses the operation as the underlying operation. + /// Delete all the rows from the table in an asynchronous way. /// /// The type of the data entity. /// The connection object to be used. @@ -471,6 +487,7 @@ public static Task DeleteAllAsync(this IDbConnection connect /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. public static Task DeleteAllAsync(this IDbConnection connection, IEnumerable keys, @@ -478,7 +495,8 @@ public static Task DeleteAllAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return DeleteAllAsyncInternal(connection: connection, @@ -488,7 +506,8 @@ public static Task DeleteAllAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -501,13 +520,15 @@ public static Task DeleteAllAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. public static Task DeleteAllAsync(this IDbConnection connection, string hints = null, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return DeleteAllAsyncInternal(connection: connection, @@ -515,7 +536,8 @@ public static Task DeleteAllAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -528,13 +550,15 @@ public static Task DeleteAllAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. internal static Task DeleteAllAsyncInternal(this IDbConnection connection, string hints = null, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { // Variables @@ -549,7 +573,8 @@ internal static Task DeleteAllAsyncInternal(this IDbConnection con request: request, commandTimeout: commandTimeout, transaction: transaction, - trace: trace); + trace: trace, + cancellationToken: cancellationToken); } #endregion @@ -742,6 +767,7 @@ internal static int DeleteAllInternal(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. public static Task DeleteAllAsync(this IDbConnection connection, string tableName, @@ -750,7 +776,8 @@ public static Task DeleteAllAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return DeleteAllAsyncInternal(connection: connection, tableName: tableName, @@ -759,7 +786,8 @@ public static Task DeleteAllAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -772,6 +800,7 @@ public static Task DeleteAllAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. public static Task DeleteAllAsync(this IDbConnection connection, string tableName, @@ -779,7 +808,8 @@ public static Task DeleteAllAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return DeleteAllAsyncInternal(connection: connection, tableName: tableName, @@ -787,7 +817,8 @@ public static Task DeleteAllAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -800,6 +831,7 @@ public static Task DeleteAllAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. internal static Task DeleteAllAsyncInternal(this IDbConnection connection, string tableName, @@ -807,7 +839,8 @@ internal static Task DeleteAllAsyncInternal(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { // Variables var request = new DeleteAllRequest(tableName, @@ -821,7 +854,8 @@ internal static Task DeleteAllAsyncInternal(this IDbConnection connection, request: request, commandTimeout: commandTimeout, transaction: transaction, - trace: trace); + trace: trace, + cancellationToken: cancellationToken); } /// @@ -835,6 +869,7 @@ internal static Task DeleteAllAsyncInternal(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. public static async Task DeleteAllAsyncInternal(this IDbConnection connection, string tableName, @@ -843,9 +878,10 @@ public static async Task DeleteAllAsyncInternal(this IDbConnection connecti int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { - var key = await GetAndGuardPrimaryKeyOrIdentityKeyAsync(connection, tableName, transaction); + var key = await GetAndGuardPrimaryKeyOrIdentityKeyAsync(connection, tableName, transaction, cancellationToken); var dbSetting = connection.GetDbSetting(); var hasImplicitTransaction = false; var count = keys?.AsList()?.Count; @@ -856,7 +892,7 @@ public static async Task DeleteAllAsyncInternal(this IDbConnection connecti // Creates a transaction (if needed) if (transaction == null && count > ParameterBatchCount) { - transaction = (await connection.EnsureOpenAsync()).BeginTransaction(); + transaction = (await connection.EnsureOpenAsync(cancellationToken)).BeginTransaction(); hasImplicitTransaction = true; } @@ -878,7 +914,8 @@ public static async Task DeleteAllAsyncInternal(this IDbConnection connecti commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } } @@ -980,12 +1017,14 @@ internal static int DeleteAllInternalBase(this IDbConnection connection, /// The command timeout in seconds to be used. /// The transaction to be used. /// The trace object to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. internal static async Task DeleteAllAsyncInternalBase(this IDbConnection connection, DeleteAllRequest request, int? commandTimeout = null, IDbTransaction transaction = null, - ITrace trace = null) + ITrace trace = null, + CancellationToken cancellationToken = default) { // Variables var commandType = CommandType.Text; @@ -1019,8 +1058,9 @@ internal static async Task DeleteAllAsyncInternalBase(this IDbConnection co commandType: commandType, commandTimeout: commandTimeout, transaction: transaction, + cancellationToken: cancellationToken, entityType: request.Type, - dbFields: await DbFieldCache.GetAsync(connection, request.Name, transaction, true), + dbFields: await DbFieldCache.GetAsync(connection, request.Name, transaction, true, cancellationToken), skipCommandArrayParametersCheck: true); // After Execution diff --git a/RepoDb.Core/RepoDb/Operations/DbConnection/Exists.cs b/RepoDb.Core/RepoDb/Operations/DbConnection/Exists.cs index a00b06978..f1184be22 100644 --- a/RepoDb.Core/RepoDb/Operations/DbConnection/Exists.cs +++ b/RepoDb.Core/RepoDb/Operations/DbConnection/Exists.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Data; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -258,6 +259,7 @@ internal static bool ExistsInternal(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// A boolean value that indicates whether the rows are existing in the table. public static async Task ExistsAsync(this IDbConnection connection, object what, @@ -265,16 +267,18 @@ public static async Task ExistsAsync(this IDbConnection connectio int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return await ExistsAsyncInternal(connection: connection, - where: await WhatToQueryGroupAsync(connection, what, transaction), + where: await WhatToQueryGroupAsync(connection, what, transaction, cancellationToken), hints: hints, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -290,22 +294,25 @@ public static async Task ExistsAsync(this IDbConnection connectio /// The trace object to be used. /// The statement builder object to be used. /// A boolean value that indicates whether the rows are existing in the table. + /// The object to be used during the asynchronous operation. public static async Task ExistsAsync(this IDbConnection connection, TWhat what, string hints = null, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return await ExistsAsyncInternal(connection: connection, - where: await WhatToQueryGroupAsync(connection, what, transaction), + where: await WhatToQueryGroupAsync(connection, what, transaction, cancellationToken), hints: hints, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -319,6 +326,7 @@ public static async Task ExistsAsync(this IDbConnection co /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// A boolean value that indicates whether the rows are existing in the table. public static Task ExistsAsync(this IDbConnection connection, Expression> where, @@ -326,7 +334,8 @@ public static Task ExistsAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return ExistsAsyncInternal(connection: connection, @@ -335,7 +344,8 @@ public static Task ExistsAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -349,6 +359,7 @@ public static Task ExistsAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// A boolean value that indicates whether the rows are existing in the table. public static Task ExistsAsync(this IDbConnection connection, QueryField where, @@ -356,7 +367,8 @@ public static Task ExistsAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return ExistsAsyncInternal(connection: connection, @@ -365,7 +377,8 @@ public static Task ExistsAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -379,6 +392,7 @@ public static Task ExistsAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// A boolean value that indicates whether the rows are existing in the table. public static Task ExistsAsync(this IDbConnection connection, IEnumerable where, @@ -386,7 +400,8 @@ public static Task ExistsAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return ExistsAsyncInternal(connection: connection, @@ -395,7 +410,8 @@ public static Task ExistsAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -409,6 +425,7 @@ public static Task ExistsAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// A boolean value that indicates whether the rows are existing in the table. public static Task ExistsAsync(this IDbConnection connection, QueryGroup where, @@ -416,7 +433,8 @@ public static Task ExistsAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return ExistsAsyncInternal(connection: connection, @@ -425,7 +443,8 @@ public static Task ExistsAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -439,6 +458,7 @@ public static Task ExistsAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// A boolean value that indicates whether the rows are existing in the table. internal static Task ExistsAsyncInternal(this IDbConnection connection, QueryGroup where, @@ -446,7 +466,8 @@ internal static Task ExistsAsyncInternal(this IDbConnection conne string hints = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { // Variables @@ -470,7 +491,8 @@ internal static Task ExistsAsyncInternal(this IDbConnection conne param: param, commandTimeout: commandTimeout, transaction: transaction, - trace: trace); + trace: trace, + cancellationToken: cancellationToken); } #endregion @@ -694,6 +716,7 @@ internal static bool ExistsInternal(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// A boolean value that indicates whether the rows are existing in the table. public static async Task ExistsAsync(this IDbConnection connection, string tableName, @@ -702,16 +725,18 @@ public static async Task ExistsAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return await ExistsAsyncInternal(connection: connection, tableName: tableName, - where: await WhatToQueryGroupAsync(connection, tableName, what, transaction), + where: await WhatToQueryGroupAsync(connection, tableName, what, transaction, cancellationToken), hints: hints, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -725,6 +750,7 @@ public static async Task ExistsAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// A boolean value that indicates whether the rows are existing in the table. public static async Task ExistsAsync(this IDbConnection connection, string tableName, @@ -733,16 +759,18 @@ public static async Task ExistsAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return await ExistsAsyncInternal(connection: connection, tableName: tableName, - where: await WhatToQueryGroupAsync(connection, tableName, what, transaction), + where: await WhatToQueryGroupAsync(connection, tableName, what, transaction, cancellationToken), hints: hints, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -756,6 +784,7 @@ public static async Task ExistsAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// A boolean value that indicates whether the rows are existing in the table. public static Task ExistsAsync(this IDbConnection connection, string tableName, @@ -764,7 +793,8 @@ public static Task ExistsAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return ExistsAsyncInternal(connection: connection, tableName: tableName, @@ -773,7 +803,8 @@ public static Task ExistsAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -787,6 +818,7 @@ public static Task ExistsAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// A boolean value that indicates whether the rows are existing in the table. public static Task ExistsAsync(this IDbConnection connection, string tableName, @@ -795,7 +827,8 @@ public static Task ExistsAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return ExistsAsyncInternal(connection: connection, tableName: tableName, @@ -804,7 +837,8 @@ public static Task ExistsAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -818,6 +852,7 @@ public static Task ExistsAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// A boolean value that indicates whether the rows are existing in the table. public static Task ExistsAsync(this IDbConnection connection, string tableName, @@ -826,7 +861,8 @@ public static Task ExistsAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return ExistsAsyncInternal(connection: connection, tableName: tableName, @@ -835,7 +871,8 @@ public static Task ExistsAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -849,6 +886,7 @@ public static Task ExistsAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// A boolean value that indicates whether the rows are existing in the table. internal static Task ExistsAsyncInternal(this IDbConnection connection, string tableName, @@ -857,7 +895,8 @@ internal static Task ExistsAsyncInternal(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { // Variables var request = new ExistsRequest(tableName, @@ -880,7 +919,8 @@ internal static Task ExistsAsyncInternal(this IDbConnection connection, param: param, commandTimeout: commandTimeout, transaction: transaction, - trace: trace); + trace: trace, + cancellationToken: cancellationToken); } #endregion @@ -965,13 +1005,15 @@ internal static bool ExistsInternalBase(this IDbConnection connection, /// The command timeout in seconds to be used. /// The transaction to be used. /// The trace object to be used. + /// The object to be used during the asynchronous operation. /// A boolean value that indicates whether the rows are existing in the table. internal static async Task ExistsAsyncInternalBase(this IDbConnection connection, ExistsRequest request, object param, int? commandTimeout = null, IDbTransaction transaction = null, - ITrace trace = null) + ITrace trace = null, + CancellationToken cancellationToken = default) { // Variables var commandType = CommandType.Text; @@ -1006,8 +1048,9 @@ internal static async Task ExistsAsyncInternalBase(this IDbConnection conn commandType: commandType, commandTimeout: commandTimeout, transaction: transaction, + cancellationToken: cancellationToken, entityType: request.Type, - dbFields: await DbFieldCache.GetAsync(connection, request.Name, transaction, true), + dbFields: await DbFieldCache.GetAsync(connection, request.Name, transaction, true, cancellationToken), skipCommandArrayParametersCheck: true); // After Execution diff --git a/RepoDb.Core/RepoDb/Operations/DbConnection/Insert.cs b/RepoDb.Core/RepoDb/Operations/DbConnection/Insert.cs index 012284bfa..cc63b34e8 100644 --- a/RepoDb.Core/RepoDb/Operations/DbConnection/Insert.cs +++ b/RepoDb.Core/RepoDb/Operations/DbConnection/Insert.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Data; using System.Data.Common; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -212,6 +213,7 @@ internal static TResult InsertInternal(this IDbConnection conn /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public static Task InsertAsync(this IDbConnection connection, string tableName, @@ -221,7 +223,8 @@ public static Task InsertAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return InsertAsyncInternal(connection: connection, @@ -232,7 +235,8 @@ public static Task InsertAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -249,6 +253,7 @@ public static Task InsertAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public static Task InsertAsync(this IDbConnection connection, string tableName, @@ -258,7 +263,8 @@ public static Task InsertAsync(this IDbConnection con int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return InsertAsyncInternal(connection: connection, @@ -269,7 +275,8 @@ public static Task InsertAsync(this IDbConnection con commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -284,6 +291,7 @@ public static Task InsertAsync(this IDbConnection con /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public static Task InsertAsync(this IDbConnection connection, TEntity entity, @@ -292,7 +300,8 @@ public static Task InsertAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return InsertAsyncInternal(connection: connection, @@ -303,7 +312,8 @@ public static Task InsertAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -319,6 +329,7 @@ public static Task InsertAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public static Task InsertAsync(this IDbConnection connection, TEntity entity, @@ -327,7 +338,8 @@ public static Task InsertAsync(this IDbConnection con int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return InsertAsyncInternal(connection: connection, @@ -338,7 +350,8 @@ public static Task InsertAsync(this IDbConnection con commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -355,6 +368,7 @@ public static Task InsertAsync(this IDbConnection con /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. internal static Task InsertAsyncInternal(this IDbConnection connection, string tableName, @@ -364,7 +378,8 @@ internal static Task InsertAsyncInternal(this IDbConn int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return InsertAsyncInternalBase(connection: connection, @@ -375,7 +390,8 @@ internal static Task InsertAsyncInternal(this IDbConn commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } #endregion @@ -468,6 +484,7 @@ public static TResult Insert(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public static Task InsertAsync(this IDbConnection connection, string tableName, @@ -477,7 +494,8 @@ public static Task InsertAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return InsertAsyncInternal(connection: connection, tableName: tableName, @@ -487,7 +505,8 @@ public static Task InsertAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -503,6 +522,7 @@ public static Task InsertAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public static Task InsertAsync(this IDbConnection connection, string tableName, @@ -512,7 +532,8 @@ public static Task InsertAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return InsertAsyncInternal(connection: connection, tableName: tableName, @@ -522,7 +543,8 @@ public static Task InsertAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } #endregion @@ -643,6 +665,7 @@ internal static TResult InsertInternalBase(this IDbConnection /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. internal async static Task InsertAsyncInternalBase(this IDbConnection connection, string tableName, @@ -652,14 +675,15 @@ internal async static Task InsertAsyncInternalBase(th int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { // Variables needed var dbSetting = connection.GetDbSetting(); // Get the database fields - var dbFields = await DbFieldCache.GetAsync(connection, tableName, transaction); + var dbFields = await DbFieldCache.GetAsync(connection, tableName, transaction, cancellationToken); // Get the context var context = await InsertExecutionContextProvider.CreateAsync(connection, @@ -667,7 +691,8 @@ internal async static Task InsertAsyncInternalBase(th fields, hints, transaction, - statementBuilder); + statementBuilder, + cancellationToken); var sessionId = Guid.Empty; // Before Execution @@ -695,19 +720,19 @@ internal async static Task InsertAsyncInternalBase(th var result = default(TResult); // Create the command - using (var command = (DbCommand)(await connection.EnsureOpenAsync()).CreateCommand(context.CommandText, + using (var command = (DbCommand)(await connection.EnsureOpenAsync(cancellationToken)).CreateCommand(context.CommandText, CommandType.Text, commandTimeout, transaction)) { // Set the values context.ParametersSetterFunc(command, entity); // Actual Execution - result = Converter.ToType(await command.ExecuteScalarAsync()); + result = Converter.ToType(await command.ExecuteScalarAsync(cancellationToken)); // Get explicity if needed if (Equals(result, default(TResult)) == true && dbSetting.IsMultiStatementExecutable == false) { - result = Converter.ToType(await connection.GetDbHelper().GetScopeIdentityAsync(connection, transaction)); + result = Converter.ToType(await connection.GetDbHelper().GetScopeIdentityAsync(connection, transaction, cancellationToken)); } // Set the return value diff --git a/RepoDb.Core/RepoDb/Operations/DbConnection/InsertAll.cs b/RepoDb.Core/RepoDb/Operations/DbConnection/InsertAll.cs index db039c1db..9c5068ef8 100644 --- a/RepoDb.Core/RepoDb/Operations/DbConnection/InsertAll.cs +++ b/RepoDb.Core/RepoDb/Operations/DbConnection/InsertAll.cs @@ -7,6 +7,7 @@ using System.Data; using System.Data.Common; using System.Linq; +using System.Threading; using System.Threading.Tasks; using System.Transactions; @@ -152,6 +153,7 @@ internal static int InsertAllInternal(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of inserted rows in the table. public static Task InsertAllAsync(this IDbConnection connection, string tableName, @@ -162,7 +164,8 @@ public static Task InsertAllAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return InsertAllAsyncInternal(connection: connection, @@ -174,7 +177,8 @@ public static Task InsertAllAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -190,6 +194,7 @@ public static Task InsertAllAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of inserted rows in the table. public static Task InsertAllAsync(this IDbConnection connection, IEnumerable entities, @@ -199,7 +204,8 @@ public static Task InsertAllAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return InsertAllAsyncInternal(connection: connection, @@ -211,7 +217,8 @@ public static Task InsertAllAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -228,6 +235,7 @@ public static Task InsertAllAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of inserted rows in the table. internal static Task InsertAllAsyncInternal(this IDbConnection connection, string tableName, @@ -238,7 +246,8 @@ internal static Task InsertAllAsyncInternal(this IDbConnection con int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return InsertAllAsyncInternalBase(connection: connection, @@ -250,7 +259,8 @@ internal static Task InsertAllAsyncInternal(this IDbConnection con commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } #endregion @@ -311,6 +321,7 @@ public static int InsertAll(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of inserted rows in the table. public static Task InsertAllAsync(this IDbConnection connection, string tableName, @@ -321,7 +332,8 @@ public static Task InsertAllAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return InsertAllAsyncInternal(connection: connection, tableName: tableName, @@ -332,7 +344,8 @@ public static Task InsertAllAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } #endregion @@ -586,6 +599,7 @@ internal static int InsertAllInternalBase(this IDbConnection connection /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of inserted rows in the table. internal static async Task InsertAllAsyncInternalBase(this IDbConnection connection, string tableName, @@ -596,7 +610,8 @@ internal static async Task InsertAllAsyncInternalBase(this IDbConn int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { // Variables needed @@ -615,7 +630,8 @@ internal static async Task InsertAllAsyncInternalBase(this IDbConn fields, hints, transaction, - statementBuilder); + statementBuilder, + cancellationToken); var sessionId = Guid.Empty; // Before Execution @@ -648,7 +664,7 @@ internal static async Task InsertAllAsyncInternalBase(this IDbConn try { // Ensure the connection is open - await connection.EnsureOpenAsync(); + await connection.EnsureOpenAsync(cancellationToken); if (hasTransaction == false) { @@ -675,12 +691,12 @@ internal static async Task InsertAllAsyncInternalBase(this IDbConn } // Actual Execution - var returnValue = Converter.DbNullToNull(await command.ExecuteScalarAsync()); + var returnValue = Converter.DbNullToNull(await command.ExecuteScalarAsync(cancellationToken)); // Get explicity if needed if (Equals(returnValue, null) == true && dbSetting.IsMultiStatementExecutable == false) { - returnValue = Converter.DbNullToNull(await connection.GetDbHelper().GetScopeIdentityAsync(connection, transaction)); + returnValue = Converter.DbNullToNull(await connection.GetDbHelper().GetScopeIdentityAsync(connection, transaction, cancellationToken)); } // Set the return value @@ -715,7 +731,8 @@ internal static async Task InsertAllAsyncInternalBase(this IDbConn fields, hints, transaction, - statementBuilder); + statementBuilder, + cancellationToken); // Set the command properties command.CommandText = context.CommandText; @@ -740,18 +757,18 @@ internal static async Task InsertAllAsyncInternalBase(this IDbConn // Actual Execution if (context.IdentityPropertySetterFunc == null) { - result += await command.ExecuteNonQueryAsync(); + result += await command.ExecuteNonQueryAsync(cancellationToken); } else { - using (var reader = await command.ExecuteReaderAsync()) + using (var reader = (DbDataReader)await command.ExecuteReaderAsync(cancellationToken)) { var index = 0; // Get the results do { - if (await reader.ReadAsync()) + if (await reader.ReadAsync(cancellationToken)) { var value = Converter.DbNullToNull(reader.GetValue(0)); context.IdentityPropertySetterFunc.Invoke(batchItems[index], value); @@ -759,7 +776,7 @@ internal static async Task InsertAllAsyncInternalBase(this IDbConn } index++; } - while (await reader.NextResultAsync()); + while (await reader.NextResultAsync(cancellationToken)); } } } diff --git a/RepoDb.Core/RepoDb/Operations/DbConnection/Max.cs b/RepoDb.Core/RepoDb/Operations/DbConnection/Max.cs index d992d51f4..e95d4bad8 100644 --- a/RepoDb.Core/RepoDb/Operations/DbConnection/Max.cs +++ b/RepoDb.Core/RepoDb/Operations/DbConnection/Max.cs @@ -7,6 +7,7 @@ using System.Data; using System.Linq; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -801,6 +802,7 @@ internal static TResult MaxInternal(this IDbConnection connect /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public static Task MaxAsync(this IDbConnection connection, Field field, @@ -809,7 +811,8 @@ public static Task MaxAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MaxAsyncInternal(connection: connection, @@ -819,7 +822,8 @@ public static Task MaxAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -834,6 +838,7 @@ public static Task MaxAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public static Task MaxAsync(this IDbConnection connection, Field field, @@ -842,7 +847,8 @@ public static Task MaxAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MaxAsyncInternal(connection: connection, @@ -852,7 +858,8 @@ public static Task MaxAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -867,6 +874,7 @@ public static Task MaxAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public static Task MaxAsync(this IDbConnection connection, Field field, @@ -875,7 +883,8 @@ public static Task MaxAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MaxAsyncInternal(connection: connection, @@ -885,7 +894,8 @@ public static Task MaxAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -900,6 +910,7 @@ public static Task MaxAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public static Task MaxAsync(this IDbConnection connection, Field field, @@ -908,7 +919,8 @@ public static Task MaxAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MaxAsyncInternal(connection: connection, @@ -918,7 +930,8 @@ public static Task MaxAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -933,6 +946,7 @@ public static Task MaxAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public static Task MaxAsync(this IDbConnection connection, Field field, @@ -941,7 +955,8 @@ public static Task MaxAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MaxAsyncInternal(connection: connection, @@ -951,7 +966,8 @@ public static Task MaxAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -966,6 +982,7 @@ public static Task MaxAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public static Task MaxAsync(this IDbConnection connection, Expression> field, @@ -974,7 +991,8 @@ public static Task MaxAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MaxAsyncInternal(connection: connection, @@ -984,7 +1002,8 @@ public static Task MaxAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -999,6 +1018,7 @@ public static Task MaxAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public static Task MaxAsync(this IDbConnection connection, Expression> field, @@ -1007,7 +1027,8 @@ public static Task MaxAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MaxAsyncInternal(connection: connection, @@ -1017,7 +1038,8 @@ public static Task MaxAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1032,6 +1054,7 @@ public static Task MaxAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public static Task MaxAsync(this IDbConnection connection, Expression> field, @@ -1040,7 +1063,8 @@ public static Task MaxAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MaxAsyncInternal(connection: connection, @@ -1050,7 +1074,8 @@ public static Task MaxAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1065,6 +1090,7 @@ public static Task MaxAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public static Task MaxAsync(this IDbConnection connection, Expression> field, @@ -1073,7 +1099,8 @@ public static Task MaxAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MaxAsyncInternal(connection: connection, @@ -1083,7 +1110,8 @@ public static Task MaxAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1098,6 +1126,7 @@ public static Task MaxAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public static Task MaxAsync(this IDbConnection connection, Expression> field, @@ -1106,7 +1135,8 @@ public static Task MaxAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MaxAsyncInternal(connection: connection, @@ -1116,7 +1146,8 @@ public static Task MaxAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1131,6 +1162,7 @@ public static Task MaxAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. internal static Task MaxAsyncInternal(this IDbConnection connection, Field field, @@ -1139,7 +1171,8 @@ internal static Task MaxAsyncInternal(this IDbConnection connec string hints = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { // Variables @@ -1164,7 +1197,8 @@ internal static Task MaxAsyncInternal(this IDbConnection connec param: param, commandTimeout: commandTimeout, transaction: transaction, - trace: trace); + trace: trace, + cancellationToken: cancellationToken); } /// @@ -1180,6 +1214,7 @@ internal static Task MaxAsyncInternal(this IDbConnection connec /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public static Task MaxAsync(this IDbConnection connection, Field field, @@ -1188,7 +1223,8 @@ public static Task MaxAsync(this IDbConnection connec int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MaxAsyncInternal(connection: connection, @@ -1198,7 +1234,8 @@ public static Task MaxAsync(this IDbConnection connec commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1214,6 +1251,7 @@ public static Task MaxAsync(this IDbConnection connec /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public static Task MaxAsync(this IDbConnection connection, Field field, @@ -1222,7 +1260,8 @@ public static Task MaxAsync(this IDbConnection connec int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MaxAsyncInternal(connection: connection, @@ -1232,7 +1271,8 @@ public static Task MaxAsync(this IDbConnection connec commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1248,6 +1288,7 @@ public static Task MaxAsync(this IDbConnection connec /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public static Task MaxAsync(this IDbConnection connection, Field field, @@ -1256,7 +1297,8 @@ public static Task MaxAsync(this IDbConnection connec int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MaxAsyncInternal(connection: connection, @@ -1266,7 +1308,8 @@ public static Task MaxAsync(this IDbConnection connec commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1282,6 +1325,7 @@ public static Task MaxAsync(this IDbConnection connec /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public static Task MaxAsync(this IDbConnection connection, Field field, @@ -1290,7 +1334,8 @@ public static Task MaxAsync(this IDbConnection connec int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MaxAsyncInternal(connection: connection, @@ -1300,7 +1345,8 @@ public static Task MaxAsync(this IDbConnection connec commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1316,6 +1362,7 @@ public static Task MaxAsync(this IDbConnection connec /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public static Task MaxAsync(this IDbConnection connection, Field field, @@ -1324,7 +1371,8 @@ public static Task MaxAsync(this IDbConnection connec int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MaxAsyncInternal(connection: connection, @@ -1334,7 +1382,8 @@ public static Task MaxAsync(this IDbConnection connec commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1350,6 +1399,7 @@ public static Task MaxAsync(this IDbConnection connec /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public static Task MaxAsync(this IDbConnection connection, Expression> field, @@ -1358,7 +1408,8 @@ public static Task MaxAsync(this IDbConnection connec int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MaxAsyncInternal(connection: connection, @@ -1368,7 +1419,8 @@ public static Task MaxAsync(this IDbConnection connec commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1384,6 +1436,7 @@ public static Task MaxAsync(this IDbConnection connec /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public static Task MaxAsync(this IDbConnection connection, Expression> field, @@ -1392,7 +1445,8 @@ public static Task MaxAsync(this IDbConnection connec int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MaxAsyncInternal(connection: connection, @@ -1402,7 +1456,8 @@ public static Task MaxAsync(this IDbConnection connec commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1418,6 +1473,7 @@ public static Task MaxAsync(this IDbConnection connec /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public static Task MaxAsync(this IDbConnection connection, Expression> field, @@ -1426,7 +1482,8 @@ public static Task MaxAsync(this IDbConnection connec int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MaxAsyncInternal(connection: connection, @@ -1436,7 +1493,8 @@ public static Task MaxAsync(this IDbConnection connec commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1452,6 +1510,7 @@ public static Task MaxAsync(this IDbConnection connec /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public static Task MaxAsync(this IDbConnection connection, Expression> field, @@ -1460,7 +1519,8 @@ public static Task MaxAsync(this IDbConnection connec int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MaxAsyncInternal(connection: connection, @@ -1470,7 +1530,8 @@ public static Task MaxAsync(this IDbConnection connec commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1486,6 +1547,7 @@ public static Task MaxAsync(this IDbConnection connec /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public static Task MaxAsync(this IDbConnection connection, Expression> field, @@ -1494,7 +1556,8 @@ public static Task MaxAsync(this IDbConnection connec int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MaxAsyncInternal(connection: connection, @@ -1504,7 +1567,8 @@ public static Task MaxAsync(this IDbConnection connec commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1520,6 +1584,7 @@ public static Task MaxAsync(this IDbConnection connec /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. internal static Task MaxAsyncInternal(this IDbConnection connection, Field field, @@ -1528,7 +1593,8 @@ internal static Task MaxAsyncInternal(this IDbConnect string hints = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { // Variables @@ -1553,7 +1619,8 @@ internal static Task MaxAsyncInternal(this IDbConnect param: param, commandTimeout: commandTimeout, transaction: transaction, - trace: trace); + trace: trace, + cancellationToken: cancellationToken); } #endregion @@ -1949,6 +2016,7 @@ internal static TResult MaxInternal(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public static Task MaxAsync(this IDbConnection connection, string tableName, @@ -1958,7 +2026,8 @@ public static Task MaxAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return MaxAsyncInternal(connection: connection, tableName: tableName, @@ -1968,7 +2037,8 @@ public static Task MaxAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1983,6 +2053,7 @@ public static Task MaxAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public static Task MaxAsync(this IDbConnection connection, string tableName, @@ -1992,7 +2063,8 @@ public static Task MaxAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return MaxAsyncInternal(connection: connection, tableName: tableName, @@ -2002,7 +2074,8 @@ public static Task MaxAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -2017,6 +2090,7 @@ public static Task MaxAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public static Task MaxAsync(this IDbConnection connection, string tableName, @@ -2026,7 +2100,8 @@ public static Task MaxAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return MaxAsyncInternal(connection: connection, tableName: tableName, @@ -2036,7 +2111,8 @@ public static Task MaxAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -2051,6 +2127,7 @@ public static Task MaxAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public static Task MaxAsync(this IDbConnection connection, string tableName, @@ -2060,7 +2137,8 @@ public static Task MaxAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return MaxAsyncInternal(connection: connection, tableName: tableName, @@ -2070,7 +2148,8 @@ public static Task MaxAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -2085,6 +2164,7 @@ public static Task MaxAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. internal static Task MaxAsyncInternal(this IDbConnection connection, string tableName, @@ -2094,7 +2174,8 @@ internal static Task MaxAsyncInternal(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { // Variables var request = new MaxRequest(tableName, @@ -2118,7 +2199,8 @@ internal static Task MaxAsyncInternal(this IDbConnection connection, param: param, commandTimeout: commandTimeout, transaction: transaction, - trace: trace); + trace: trace, + cancellationToken: cancellationToken); } /// @@ -2134,6 +2216,7 @@ internal static Task MaxAsyncInternal(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public static Task MaxAsync(this IDbConnection connection, string tableName, @@ -2143,7 +2226,8 @@ public static Task MaxAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return MaxAsyncInternal(connection: connection, tableName: tableName, @@ -2153,7 +2237,8 @@ public static Task MaxAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -2169,6 +2254,7 @@ public static Task MaxAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public static Task MaxAsync(this IDbConnection connection, string tableName, @@ -2178,7 +2264,8 @@ public static Task MaxAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return MaxAsyncInternal(connection: connection, tableName: tableName, @@ -2188,7 +2275,8 @@ public static Task MaxAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -2204,6 +2292,7 @@ public static Task MaxAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public static Task MaxAsync(this IDbConnection connection, string tableName, @@ -2213,7 +2302,8 @@ public static Task MaxAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return MaxAsyncInternal(connection: connection, tableName: tableName, @@ -2223,7 +2313,8 @@ public static Task MaxAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -2239,6 +2330,7 @@ public static Task MaxAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public static Task MaxAsync(this IDbConnection connection, string tableName, @@ -2248,7 +2340,8 @@ public static Task MaxAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return MaxAsyncInternal(connection: connection, tableName: tableName, @@ -2258,7 +2351,8 @@ public static Task MaxAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -2274,6 +2368,7 @@ public static Task MaxAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. internal static Task MaxAsyncInternal(this IDbConnection connection, string tableName, @@ -2283,7 +2378,8 @@ internal static Task MaxAsyncInternal(this IDbConnection conne int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { // Variables var request = new MaxRequest(tableName, @@ -2307,7 +2403,8 @@ internal static Task MaxAsyncInternal(this IDbConnection conne param: param, commandTimeout: commandTimeout, transaction: transaction, - trace: trace); + trace: trace, + cancellationToken: cancellationToken); } #endregion @@ -2392,13 +2489,15 @@ internal static TResult MaxInternalBase(this IDbConnection connection, /// The command timeout in seconds to be used. /// The transaction to be used. /// The trace object to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. internal static async Task MaxAsyncInternalBase(this IDbConnection connection, MaxRequest request, object param, int? commandTimeout = null, IDbTransaction transaction = null, - ITrace trace = null) + ITrace trace = null, + CancellationToken cancellationToken = default) { // Variables var commandType = CommandType.Text; @@ -2433,8 +2532,9 @@ internal static async Task MaxAsyncInternalBase(this IDbConnec commandType: commandType, commandTimeout: commandTimeout, transaction: transaction, + cancellationToken: cancellationToken, entityType: request.Type, - dbFields: await DbFieldCache.GetAsync(connection, request.Name, transaction, true), + dbFields: await DbFieldCache.GetAsync(connection, request.Name, transaction, true, cancellationToken), skipCommandArrayParametersCheck: true); // After Execution diff --git a/RepoDb.Core/RepoDb/Operations/DbConnection/MaxAll.cs b/RepoDb.Core/RepoDb/Operations/DbConnection/MaxAll.cs index 1dfad5ccc..40f5a726c 100644 --- a/RepoDb.Core/RepoDb/Operations/DbConnection/MaxAll.cs +++ b/RepoDb.Core/RepoDb/Operations/DbConnection/MaxAll.cs @@ -5,6 +5,7 @@ using System.Data; using System.Linq; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -193,6 +194,7 @@ internal static TResult MaxAllInternal(this IDbConnection conn /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public static Task MaxAllAsync(this IDbConnection connection, Field field, @@ -200,7 +202,8 @@ public static Task MaxAllAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MaxAllAsyncInternal(connection: connection, @@ -209,7 +212,8 @@ public static Task MaxAllAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -223,6 +227,7 @@ public static Task MaxAllAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public static Task MaxAllAsync(this IDbConnection connection, Expression> field, @@ -230,7 +235,8 @@ public static Task MaxAllAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MaxAllAsyncInternal(connection: connection, @@ -239,7 +245,8 @@ public static Task MaxAllAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -254,6 +261,7 @@ public static Task MaxAllAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public static Task MaxAllAsync(this IDbConnection connection, Field field, @@ -261,7 +269,8 @@ public static Task MaxAllAsync(this IDbConnection con int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MaxAllAsyncInternal(connection: connection, @@ -270,7 +279,8 @@ public static Task MaxAllAsync(this IDbConnection con commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -285,6 +295,7 @@ public static Task MaxAllAsync(this IDbConnection con /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public static Task MaxAllAsync(this IDbConnection connection, Expression> field, @@ -292,7 +303,8 @@ public static Task MaxAllAsync(this IDbConnection con int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MaxAllAsyncInternal(connection: connection, @@ -301,7 +313,8 @@ public static Task MaxAllAsync(this IDbConnection con commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -316,6 +329,7 @@ public static Task MaxAllAsync(this IDbConnection con /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. internal static Task MaxAllAsyncInternal(this IDbConnection connection, Field field, @@ -323,7 +337,8 @@ internal static Task MaxAllAsyncInternal(this IDbConn int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { // Variables @@ -341,7 +356,8 @@ internal static Task MaxAllAsyncInternal(this IDbConn param: param, commandTimeout: commandTimeout, transaction: transaction, - trace: trace); + trace: trace, + cancellationToken: cancellationToken); } #endregion @@ -465,6 +481,7 @@ internal static TResult MaxAllInternal(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public static Task MaxAllAsync(this IDbConnection connection, string tableName, @@ -473,7 +490,8 @@ public static Task MaxAllAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return MaxAllAsyncInternal(connection: connection, tableName: tableName, @@ -482,7 +500,8 @@ public static Task MaxAllAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -497,6 +516,7 @@ public static Task MaxAllAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public static Task MaxAllAsync(this IDbConnection connection, string tableName, @@ -505,7 +525,8 @@ public static Task MaxAllAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return MaxAllAsyncInternal(connection: connection, tableName: tableName, @@ -514,7 +535,8 @@ public static Task MaxAllAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -529,6 +551,7 @@ public static Task MaxAllAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. internal static Task MaxAllAsyncInternal(this IDbConnection connection, string tableName, @@ -537,7 +560,8 @@ internal static Task MaxAllAsyncInternal(this IDbConnection co int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { // Variables var request = new MaxAllRequest(tableName, @@ -553,7 +577,8 @@ internal static Task MaxAllAsyncInternal(this IDbConnection co param: null, commandTimeout: commandTimeout, transaction: transaction, - trace: trace); + trace: trace, + cancellationToken: cancellationToken); } #endregion @@ -640,13 +665,15 @@ internal static TResult MaxAllInternalBase(this IDbConnection connectio /// The command timeout in seconds to be used. /// The transaction to be used. /// The trace object to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. internal static async Task MaxAllAsyncInternalBase(this IDbConnection connection, MaxAllRequest request, object param, int? commandTimeout = null, IDbTransaction transaction = null, - ITrace trace = null) + ITrace trace = null, + CancellationToken cancellationToken = default) { // Variables var commandType = CommandType.Text; @@ -681,8 +708,9 @@ internal static async Task MaxAllAsyncInternalBase(this IDbCon commandType: commandType, commandTimeout: commandTimeout, transaction: transaction, + cancellationToken: cancellationToken, entityType: request.Type, - dbFields: await DbFieldCache.GetAsync(connection, request.Name, transaction, true), + dbFields: await DbFieldCache.GetAsync(connection, request.Name, transaction, true, cancellationToken), skipCommandArrayParametersCheck: true); // After Execution diff --git a/RepoDb.Core/RepoDb/Operations/DbConnection/Merge.cs b/RepoDb.Core/RepoDb/Operations/DbConnection/Merge.cs index 9c689bebb..79a334011 100644 --- a/RepoDb.Core/RepoDb/Operations/DbConnection/Merge.cs +++ b/RepoDb.Core/RepoDb/Operations/DbConnection/Merge.cs @@ -8,6 +8,7 @@ using System.Data.Common; using System.Linq; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -704,6 +705,7 @@ internal static TResult MergeInternal(this IDbConnection conne /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public static Task MergeAsync(this IDbConnection connection, string tableName, @@ -713,7 +715,8 @@ public static Task MergeAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MergeAsyncInternal(connection: connection, @@ -725,7 +728,8 @@ public static Task MergeAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -742,6 +746,7 @@ public static Task MergeAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public static Task MergeAsync(this IDbConnection connection, string tableName, @@ -752,7 +757,8 @@ public static Task MergeAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MergeAsyncInternal(connection: connection, @@ -764,7 +770,8 @@ public static Task MergeAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -781,6 +788,7 @@ public static Task MergeAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public static Task MergeAsync(this IDbConnection connection, string tableName, @@ -791,7 +799,8 @@ public static Task MergeAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MergeAsyncInternal(connection: connection, @@ -803,7 +812,8 @@ public static Task MergeAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -820,6 +830,7 @@ public static Task MergeAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public static Task MergeAsync(this IDbConnection connection, string tableName, @@ -830,7 +841,8 @@ public static Task MergeAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MergeAsyncInternal(connection: connection, @@ -842,7 +854,8 @@ public static Task MergeAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -859,6 +872,7 @@ public static Task MergeAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public static Task MergeAsync(this IDbConnection connection, string tableName, @@ -868,7 +882,8 @@ public static Task MergeAsync(this IDbConnection conn int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MergeAsyncInternal(connection: connection, @@ -880,7 +895,8 @@ public static Task MergeAsync(this IDbConnection conn commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -898,6 +914,7 @@ public static Task MergeAsync(this IDbConnection conn /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public static Task MergeAsync(this IDbConnection connection, string tableName, @@ -908,7 +925,8 @@ public static Task MergeAsync(this IDbConnection conn int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MergeAsyncInternal(connection: connection, @@ -920,7 +938,8 @@ public static Task MergeAsync(this IDbConnection conn commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -938,6 +957,7 @@ public static Task MergeAsync(this IDbConnection conn /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public static Task MergeAsync(this IDbConnection connection, string tableName, @@ -948,7 +968,8 @@ public static Task MergeAsync(this IDbConnection conn int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MergeAsyncInternal(connection: connection, @@ -960,7 +981,8 @@ public static Task MergeAsync(this IDbConnection conn commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -978,6 +1000,7 @@ public static Task MergeAsync(this IDbConnection conn /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public static Task MergeAsync(this IDbConnection connection, string tableName, @@ -988,7 +1011,8 @@ public static Task MergeAsync(this IDbConnection conn int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MergeAsyncInternal(connection: connection, @@ -1000,7 +1024,8 @@ public static Task MergeAsync(this IDbConnection conn commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1015,6 +1040,7 @@ public static Task MergeAsync(this IDbConnection conn /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public static Task MergeAsync(this IDbConnection connection, TEntity entity, @@ -1023,7 +1049,8 @@ public static Task MergeAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MergeAsyncInternal(connection: connection, @@ -1035,7 +1062,8 @@ public static Task MergeAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1051,6 +1079,7 @@ public static Task MergeAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public static Task MergeAsync(this IDbConnection connection, TEntity entity, @@ -1060,7 +1089,8 @@ public static Task MergeAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MergeAsyncInternal(connection: connection, @@ -1072,7 +1102,8 @@ public static Task MergeAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1088,6 +1119,7 @@ public static Task MergeAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public static Task MergeAsync(this IDbConnection connection, TEntity entity, @@ -1097,7 +1129,8 @@ public static Task MergeAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MergeAsyncInternal(connection: connection, @@ -1109,7 +1142,8 @@ public static Task MergeAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1125,6 +1159,7 @@ public static Task MergeAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public static Task MergeAsync(this IDbConnection connection, TEntity entity, @@ -1134,7 +1169,8 @@ public static Task MergeAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MergeAsyncInternal(connection: connection, @@ -1146,7 +1182,8 @@ public static Task MergeAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1162,6 +1199,7 @@ public static Task MergeAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public static Task MergeAsync(this IDbConnection connection, TEntity entity, @@ -1170,7 +1208,8 @@ public static Task MergeAsync(this IDbConnection conn int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MergeAsyncInternal(connection: connection, @@ -1182,7 +1221,8 @@ public static Task MergeAsync(this IDbConnection conn commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1199,6 +1239,7 @@ public static Task MergeAsync(this IDbConnection conn /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public static Task MergeAsync(this IDbConnection connection, TEntity entity, @@ -1208,7 +1249,8 @@ public static Task MergeAsync(this IDbConnection conn int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MergeAsyncInternal(connection: connection, @@ -1220,7 +1262,8 @@ public static Task MergeAsync(this IDbConnection conn commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1237,6 +1280,7 @@ public static Task MergeAsync(this IDbConnection conn /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public static Task MergeAsync(this IDbConnection connection, TEntity entity, @@ -1246,7 +1290,8 @@ public static Task MergeAsync(this IDbConnection conn int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MergeAsyncInternal(connection: connection, @@ -1258,7 +1303,8 @@ public static Task MergeAsync(this IDbConnection conn commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1275,6 +1321,7 @@ public static Task MergeAsync(this IDbConnection conn /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public static Task MergeAsync(this IDbConnection connection, TEntity entity, @@ -1284,7 +1331,8 @@ public static Task MergeAsync(this IDbConnection conn int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MergeAsyncInternal(connection: connection, @@ -1296,7 +1344,8 @@ public static Task MergeAsync(this IDbConnection conn commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1314,6 +1363,7 @@ public static Task MergeAsync(this IDbConnection conn /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. internal static async Task MergeAsyncInternal(this IDbConnection connection, string tableName, @@ -1324,7 +1374,8 @@ internal static async Task MergeAsyncInternal(this ID int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { // Variables needed @@ -1342,7 +1393,8 @@ internal static async Task MergeAsyncInternal(this ID commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } else { @@ -1355,7 +1407,8 @@ internal static async Task MergeAsyncInternal(this ID commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } } @@ -1600,6 +1653,7 @@ public static TResult Merge(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public static Task MergeAsync(this IDbConnection connection, string tableName, @@ -1609,7 +1663,8 @@ public static Task MergeAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return MergeAsyncInternal(connection: connection, tableName: tableName, @@ -1620,7 +1675,8 @@ public static Task MergeAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1636,6 +1692,7 @@ public static Task MergeAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public static Task MergeAsync(this IDbConnection connection, string tableName, @@ -1646,7 +1703,8 @@ public static Task MergeAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return MergeAsyncInternal(connection: connection, tableName: tableName, @@ -1657,7 +1715,8 @@ public static Task MergeAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1673,6 +1732,7 @@ public static Task MergeAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public static Task MergeAsync(this IDbConnection connection, string tableName, @@ -1683,7 +1743,8 @@ public static Task MergeAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return MergeAsyncInternal(connection: connection, tableName: tableName, @@ -1694,7 +1755,8 @@ public static Task MergeAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1710,6 +1772,7 @@ public static Task MergeAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public static Task MergeAsync(this IDbConnection connection, string tableName, @@ -1719,7 +1782,8 @@ public static Task MergeAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return MergeAsyncInternal(connection: connection, tableName: tableName, @@ -1730,7 +1794,8 @@ public static Task MergeAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1747,6 +1812,7 @@ public static Task MergeAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public static Task MergeAsync(this IDbConnection connection, string tableName, @@ -1757,7 +1823,8 @@ public static Task MergeAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return MergeAsyncInternal(connection: connection, tableName: tableName, @@ -1768,7 +1835,8 @@ public static Task MergeAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1785,6 +1853,7 @@ public static Task MergeAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public static Task MergeAsync(this IDbConnection connection, string tableName, @@ -1795,7 +1864,8 @@ public static Task MergeAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return MergeAsyncInternal(connection: connection, tableName: tableName, @@ -1806,7 +1876,8 @@ public static Task MergeAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } #endregion @@ -2089,6 +2160,7 @@ internal static TResult UpsertInternalBase(this IDbConnection /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. internal static async Task MergeAsyncInternalBase(this IDbConnection connection, string tableName, @@ -2099,14 +2171,15 @@ internal static async Task MergeAsyncInternalBase(thi int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { // Check the qualifiers if (qualifiers?.Any() != true) { var key = await GetAndGuardPrimaryKeyOrIdentityKeyAsync(connection, tableName, transaction, - entity?.GetType() ?? typeof(TEntity)); + entity?.GetType() ?? typeof(TEntity), cancellationToken); qualifiers = key.AsField().AsEnumerable(); } @@ -2117,7 +2190,8 @@ internal static async Task MergeAsyncInternalBase(thi fields, hints, transaction, - statementBuilder); + statementBuilder, + cancellationToken); var sessionId = Guid.Empty; // Before Execution @@ -2145,14 +2219,14 @@ internal static async Task MergeAsyncInternalBase(thi var result = default(TResult); // Create the command - using (var command = (DbCommand)(await connection.EnsureOpenAsync()).CreateCommand(context.CommandText, + using (var command = (DbCommand)(await connection.EnsureOpenAsync(cancellationToken)).CreateCommand(context.CommandText, CommandType.Text, commandTimeout, transaction)) { // Set the values context.ParametersSetterFunc(command, entity); // Actual Execution - result = Converter.ToType(await command.ExecuteScalarAsync()); + result = Converter.ToType(await command.ExecuteScalarAsync(cancellationToken)); // Set the return value if (Equals(result, default(TResult)) == false) @@ -2191,6 +2265,7 @@ internal static async Task MergeAsyncInternalBase(thi /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. internal static async Task UpsertAsyncInternalBase(this IDbConnection connection, string tableName, @@ -2201,12 +2276,13 @@ internal static async Task UpsertAsyncInternalBase(th int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { // Variables needed var type = entity?.GetType() ?? typeof(TEntity); - var dbFields = await DbFieldCache.GetAsync(connection, tableName, transaction); + var dbFields = await DbFieldCache.GetAsync(connection, tableName, transaction, cancellationToken); var primary = dbFields?.FirstOrDefault(dbField => dbField.IsPrimary); var properties = (IEnumerable)null; var primaryKey = (ClassProperty)null; @@ -2278,7 +2354,8 @@ internal static async Task UpsertAsyncInternalBase(th commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); // Check the existence if (exists == true) @@ -2292,7 +2369,8 @@ internal static async Task UpsertAsyncInternalBase(th commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); // Check if there is result if (updateResult > 0) @@ -2314,7 +2392,8 @@ internal static async Task UpsertAsyncInternalBase(th commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); // Set the result result = Converter.ToType(insertResult); diff --git a/RepoDb.Core/RepoDb/Operations/DbConnection/MergeAll.cs b/RepoDb.Core/RepoDb/Operations/DbConnection/MergeAll.cs index b3d436ca2..776b55b65 100644 --- a/RepoDb.Core/RepoDb/Operations/DbConnection/MergeAll.cs +++ b/RepoDb.Core/RepoDb/Operations/DbConnection/MergeAll.cs @@ -8,6 +8,7 @@ using System.Data.Common; using System.Linq; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; using System.Transactions; @@ -432,6 +433,7 @@ internal static int MergeAllInternal(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the merge process. public static Task MergeAllAsync(this IDbConnection connection, string tableName, @@ -442,7 +444,8 @@ public static Task MergeAllAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MergeAllAsyncInternal(connection: connection, @@ -455,7 +458,8 @@ public static Task MergeAllAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -473,6 +477,7 @@ public static Task MergeAllAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the merge process. public static Task MergeAllAsync(this IDbConnection connection, string tableName, @@ -484,7 +489,8 @@ public static Task MergeAllAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MergeAllAsyncInternal(connection: connection, @@ -497,7 +503,8 @@ public static Task MergeAllAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -515,6 +522,7 @@ public static Task MergeAllAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the merge process. public static Task MergeAllAsync(this IDbConnection connection, string tableName, @@ -526,7 +534,8 @@ public static Task MergeAllAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MergeAllAsyncInternal(connection: connection, @@ -539,7 +548,8 @@ public static Task MergeAllAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -557,6 +567,7 @@ public static Task MergeAllAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the merge process. public static Task MergeAllAsync(this IDbConnection connection, string tableName, @@ -568,7 +579,8 @@ public static Task MergeAllAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MergeAllAsyncInternal(connection: connection, @@ -581,7 +593,8 @@ public static Task MergeAllAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -597,6 +610,7 @@ public static Task MergeAllAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the merge process. public static Task MergeAllAsync(this IDbConnection connection, IEnumerable entities, @@ -606,7 +620,8 @@ public static Task MergeAllAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MergeAllAsyncInternal(connection: connection, @@ -619,7 +634,8 @@ public static Task MergeAllAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -636,6 +652,7 @@ public static Task MergeAllAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the merge process. public static Task MergeAllAsync(this IDbConnection connection, IEnumerable entities, @@ -646,7 +663,8 @@ public static Task MergeAllAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MergeAllAsyncInternal(connection: connection, @@ -659,7 +677,8 @@ public static Task MergeAllAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -676,6 +695,7 @@ public static Task MergeAllAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the merge process. public static Task MergeAllAsync(this IDbConnection connection, IEnumerable entities, @@ -686,7 +706,8 @@ public static Task MergeAllAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MergeAllAsyncInternal(connection: connection, @@ -699,7 +720,8 @@ public static Task MergeAllAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -716,6 +738,7 @@ public static Task MergeAllAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the merge process. public static Task MergeAllAsync(this IDbConnection connection, IEnumerable entities, @@ -726,7 +749,8 @@ public static Task MergeAllAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MergeAllAsyncInternal(connection: connection, @@ -739,7 +763,8 @@ public static Task MergeAllAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -757,6 +782,7 @@ public static Task MergeAllAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the merge process. internal static async Task MergeAllAsyncInternal(this IDbConnection connection, string tableName, @@ -768,14 +794,15 @@ internal static async Task MergeAllAsyncInternal(this IDbConnectio int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { // Check the qualifiers if (qualifiers?.Any() != true) { var key = await GetAndGuardPrimaryKeyOrIdentityKeyAsync(connection, tableName, transaction, - entities?.FirstOrDefault()?.GetType() ?? typeof(TEntity)); + entities?.FirstOrDefault()?.GetType() ?? typeof(TEntity), cancellationToken); qualifiers = key.AsField().AsEnumerable(); } @@ -795,7 +822,8 @@ internal static async Task MergeAllAsyncInternal(this IDbConnectio commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } else { @@ -808,7 +836,8 @@ internal static async Task MergeAllAsyncInternal(this IDbConnectio commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } } @@ -951,6 +980,7 @@ public static int MergeAll(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the merge process. public static Task MergeAllAsync(this IDbConnection connection, string tableName, @@ -961,7 +991,8 @@ public static Task MergeAllAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return MergeAllAsyncInternal(connection: connection, tableName: tableName, @@ -973,7 +1004,8 @@ public static Task MergeAllAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -990,6 +1022,7 @@ public static Task MergeAllAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the merge process. public static Task MergeAllAsync(this IDbConnection connection, string tableName, @@ -1001,7 +1034,8 @@ public static Task MergeAllAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return MergeAllAsyncInternal(connection: connection, tableName: tableName, @@ -1013,7 +1047,8 @@ public static Task MergeAllAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1030,6 +1065,7 @@ public static Task MergeAllAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the merge process. public static Task MergeAllAsync(this IDbConnection connection, string tableName, @@ -1041,7 +1077,8 @@ public static Task MergeAllAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return MergeAllAsyncInternal(connection: connection, tableName: tableName, @@ -1053,7 +1090,8 @@ public static Task MergeAllAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } #endregion @@ -1470,6 +1508,7 @@ internal static int UpsertAllInternalBase(this IDbConnection connection /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the merge process. internal static async Task MergeAllAsyncInternalBase(this IDbConnection connection, string tableName, @@ -1481,7 +1520,8 @@ internal static async Task MergeAllAsyncInternalBase(this IDbConne int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { // Variables needed @@ -1502,7 +1542,8 @@ internal static async Task MergeAllAsyncInternalBase(this IDbConne fields, hints, transaction, - statementBuilder); + statementBuilder, + cancellationToken); var sessionId = Guid.Empty; // Before Execution @@ -1535,7 +1576,7 @@ internal static async Task MergeAllAsyncInternalBase(this IDbConne try { // Ensure the connection is open - await connection.EnsureOpenAsync(); + await connection.EnsureOpenAsync(cancellationToken); if (hasTransaction == false) { @@ -1563,7 +1604,7 @@ internal static async Task MergeAllAsyncInternalBase(this IDbConne } // Actual Execution - var returnValue = Converter.DbNullToNull(await command.ExecuteScalarAsync()); + var returnValue = Converter.DbNullToNull(await command.ExecuteScalarAsync(cancellationToken)); // Set the return value if (returnValue != null) @@ -1600,7 +1641,8 @@ internal static async Task MergeAllAsyncInternalBase(this IDbConne fields, hints, transaction, - statementBuilder); + statementBuilder, + cancellationToken); // Set the command properties command.CommandText = context.CommandText; @@ -1626,17 +1668,17 @@ internal static async Task MergeAllAsyncInternalBase(this IDbConne if (context.IdentityPropertySetterFunc == null) { // No identity setters - result += await command.ExecuteNonQueryAsync(); + result += await command.ExecuteNonQueryAsync(cancellationToken); } else { // Set the identity back - using (var reader = await command.ExecuteReaderAsync()) + using (var reader = await command.ExecuteReaderAsync(cancellationToken)) { var index = 0; do { - if (await reader.ReadAsync()) + if (await reader.ReadAsync(cancellationToken)) { var value = Converter.DbNullToNull(reader.GetValue(0)); context.IdentityPropertySetterFunc.Invoke(batchItems[index], value); @@ -1644,7 +1686,7 @@ internal static async Task MergeAllAsyncInternalBase(this IDbConne } index++; } - while (await reader.NextResultAsync()); + while (await reader.NextResultAsync(cancellationToken)); } } } @@ -1704,6 +1746,7 @@ internal static async Task MergeAllAsyncInternalBase(this IDbConne /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the merge process. internal static async Task UpsertAllAsyncInternalBase(this IDbConnection connection, string tableName, @@ -1714,13 +1757,14 @@ internal static async Task UpsertAllAsyncInternalBase(this IDbConn int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { // Variables needed var type = entities?.FirstOrDefault()?.GetType() ?? typeof(TEntity); var isObjectType = typeof(TEntity) == StaticType.Object; - var dbFields = await DbFieldCache.GetAsync(connection, tableName, transaction); + var dbFields = await DbFieldCache.GetAsync(connection, tableName, transaction, cancellationToken); var primary = dbFields?.FirstOrDefault(dbField => dbField.IsPrimary); var properties = (IEnumerable)null; var primaryKey = (ClassProperty)null; @@ -1782,7 +1826,7 @@ internal static async Task UpsertAllAsyncInternalBase(this IDbConn try { // Ensure to open the connection - await connection.EnsureOpenAsync(); + await connection.EnsureOpenAsync(cancellationToken); // Create a transaction if (hasTransaction == false) @@ -1802,7 +1846,8 @@ internal static async Task UpsertAllAsyncInternalBase(this IDbConn commandTimeout, transaction, trace, - statementBuilder); + statementBuilder, + cancellationToken: cancellationToken); // Iterate the result if (Converter.DbNullToNull(upsertResult) != null) diff --git a/RepoDb.Core/RepoDb/Operations/DbConnection/Min.cs b/RepoDb.Core/RepoDb/Operations/DbConnection/Min.cs index 91c212b38..f0aee8576 100644 --- a/RepoDb.Core/RepoDb/Operations/DbConnection/Min.cs +++ b/RepoDb.Core/RepoDb/Operations/DbConnection/Min.cs @@ -7,6 +7,7 @@ using System.Data; using System.Linq; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -801,6 +802,7 @@ internal static TResult MinInternal(this IDbConnection connect /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public static Task MinAsync(this IDbConnection connection, Field field, @@ -809,7 +811,8 @@ public static Task MinAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MinAsyncInternal(connection: connection, @@ -819,7 +822,8 @@ public static Task MinAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -834,6 +838,7 @@ public static Task MinAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public static Task MinAsync(this IDbConnection connection, Field field, @@ -842,7 +847,8 @@ public static Task MinAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MinAsyncInternal(connection: connection, @@ -852,7 +858,8 @@ public static Task MinAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -867,6 +874,7 @@ public static Task MinAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public static Task MinAsync(this IDbConnection connection, Field field, @@ -875,7 +883,8 @@ public static Task MinAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MinAsyncInternal(connection: connection, @@ -885,7 +894,8 @@ public static Task MinAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -900,6 +910,7 @@ public static Task MinAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public static Task MinAsync(this IDbConnection connection, Field field, @@ -908,7 +919,8 @@ public static Task MinAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MinAsyncInternal(connection: connection, @@ -918,7 +930,8 @@ public static Task MinAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -933,6 +946,7 @@ public static Task MinAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public static Task MinAsync(this IDbConnection connection, Field field, @@ -941,7 +955,8 @@ public static Task MinAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MinAsyncInternal(connection: connection, @@ -951,7 +966,8 @@ public static Task MinAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -966,6 +982,7 @@ public static Task MinAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public static Task MinAsync(this IDbConnection connection, Expression> field, @@ -974,7 +991,8 @@ public static Task MinAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MinAsyncInternal(connection: connection, @@ -984,7 +1002,8 @@ public static Task MinAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -999,6 +1018,7 @@ public static Task MinAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public static Task MinAsync(this IDbConnection connection, Expression> field, @@ -1007,7 +1027,8 @@ public static Task MinAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MinAsyncInternal(connection: connection, @@ -1017,7 +1038,8 @@ public static Task MinAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1032,6 +1054,7 @@ public static Task MinAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public static Task MinAsync(this IDbConnection connection, Expression> field, @@ -1040,7 +1063,8 @@ public static Task MinAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MinAsyncInternal(connection: connection, @@ -1050,7 +1074,8 @@ public static Task MinAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1065,6 +1090,7 @@ public static Task MinAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public static Task MinAsync(this IDbConnection connection, Expression> field, @@ -1073,7 +1099,8 @@ public static Task MinAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MinAsyncInternal(connection: connection, @@ -1083,7 +1110,8 @@ public static Task MinAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1098,6 +1126,7 @@ public static Task MinAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public static Task MinAsync(this IDbConnection connection, Expression> field, @@ -1106,7 +1135,8 @@ public static Task MinAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MinAsyncInternal(connection: connection, @@ -1116,7 +1146,8 @@ public static Task MinAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1131,6 +1162,7 @@ public static Task MinAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. internal static Task MinAsyncInternal(this IDbConnection connection, Field field, @@ -1139,7 +1171,8 @@ internal static Task MinAsyncInternal(this IDbConnection connec string hints = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { // Variables @@ -1164,7 +1197,8 @@ internal static Task MinAsyncInternal(this IDbConnection connec param: param, commandTimeout: commandTimeout, transaction: transaction, - trace: trace); + trace: trace, + cancellationToken: cancellationToken); } /// @@ -1180,6 +1214,7 @@ internal static Task MinAsyncInternal(this IDbConnection connec /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public static Task MinAsync(this IDbConnection connection, Field field, @@ -1188,7 +1223,8 @@ public static Task MinAsync(this IDbConnection connec int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MinAsyncInternal(connection: connection, @@ -1198,7 +1234,8 @@ public static Task MinAsync(this IDbConnection connec commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1214,6 +1251,7 @@ public static Task MinAsync(this IDbConnection connec /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public static Task MinAsync(this IDbConnection connection, Field field, @@ -1222,7 +1260,8 @@ public static Task MinAsync(this IDbConnection connec int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MinAsyncInternal(connection: connection, @@ -1232,7 +1271,8 @@ public static Task MinAsync(this IDbConnection connec commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1248,6 +1288,7 @@ public static Task MinAsync(this IDbConnection connec /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public static Task MinAsync(this IDbConnection connection, Field field, @@ -1256,7 +1297,8 @@ public static Task MinAsync(this IDbConnection connec int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MinAsyncInternal(connection: connection, @@ -1266,7 +1308,8 @@ public static Task MinAsync(this IDbConnection connec commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1282,6 +1325,7 @@ public static Task MinAsync(this IDbConnection connec /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public static Task MinAsync(this IDbConnection connection, Field field, @@ -1290,7 +1334,8 @@ public static Task MinAsync(this IDbConnection connec int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MinAsyncInternal(connection: connection, @@ -1300,7 +1345,8 @@ public static Task MinAsync(this IDbConnection connec commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1316,6 +1362,7 @@ public static Task MinAsync(this IDbConnection connec /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public static Task MinAsync(this IDbConnection connection, Field field, @@ -1324,7 +1371,8 @@ public static Task MinAsync(this IDbConnection connec int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MinAsyncInternal(connection: connection, @@ -1334,7 +1382,8 @@ public static Task MinAsync(this IDbConnection connec commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1350,6 +1399,7 @@ public static Task MinAsync(this IDbConnection connec /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public static Task MinAsync(this IDbConnection connection, Expression> field, @@ -1358,7 +1408,8 @@ public static Task MinAsync(this IDbConnection connec int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MinAsyncInternal(connection: connection, @@ -1368,7 +1419,8 @@ public static Task MinAsync(this IDbConnection connec commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1384,6 +1436,7 @@ public static Task MinAsync(this IDbConnection connec /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public static Task MinAsync(this IDbConnection connection, Expression> field, @@ -1392,7 +1445,8 @@ public static Task MinAsync(this IDbConnection connec int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MinAsyncInternal(connection: connection, @@ -1402,7 +1456,8 @@ public static Task MinAsync(this IDbConnection connec commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1418,6 +1473,7 @@ public static Task MinAsync(this IDbConnection connec /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public static Task MinAsync(this IDbConnection connection, Expression> field, @@ -1426,7 +1482,8 @@ public static Task MinAsync(this IDbConnection connec int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MinAsyncInternal(connection: connection, @@ -1436,7 +1493,8 @@ public static Task MinAsync(this IDbConnection connec commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1452,6 +1510,7 @@ public static Task MinAsync(this IDbConnection connec /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public static Task MinAsync(this IDbConnection connection, Expression> field, @@ -1460,7 +1519,8 @@ public static Task MinAsync(this IDbConnection connec int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MinAsyncInternal(connection: connection, @@ -1470,7 +1530,8 @@ public static Task MinAsync(this IDbConnection connec commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1486,6 +1547,7 @@ public static Task MinAsync(this IDbConnection connec /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public static Task MinAsync(this IDbConnection connection, Expression> field, @@ -1494,7 +1556,8 @@ public static Task MinAsync(this IDbConnection connec int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MinAsyncInternal(connection: connection, @@ -1504,7 +1567,8 @@ public static Task MinAsync(this IDbConnection connec commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1520,6 +1584,7 @@ public static Task MinAsync(this IDbConnection connec /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. internal static Task MinAsyncInternal(this IDbConnection connection, Field field, @@ -1528,7 +1593,8 @@ internal static Task MinAsyncInternal(this IDbConnect string hints = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { // Variables @@ -1553,7 +1619,8 @@ internal static Task MinAsyncInternal(this IDbConnect param: param, commandTimeout: commandTimeout, transaction: transaction, - trace: trace); + trace: trace, + cancellationToken: cancellationToken); } #endregion @@ -1949,6 +2016,7 @@ internal static TResult MinInternal(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public static Task MinAsync(this IDbConnection connection, string tableName, @@ -1958,7 +2026,8 @@ public static Task MinAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return MinAsyncInternal(connection: connection, tableName: tableName, @@ -1968,7 +2037,8 @@ public static Task MinAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1983,6 +2053,7 @@ public static Task MinAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public static Task MinAsync(this IDbConnection connection, string tableName, @@ -1992,7 +2063,8 @@ public static Task MinAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return MinAsyncInternal(connection: connection, tableName: tableName, @@ -2002,7 +2074,8 @@ public static Task MinAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -2017,6 +2090,7 @@ public static Task MinAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public static Task MinAsync(this IDbConnection connection, string tableName, @@ -2026,7 +2100,8 @@ public static Task MinAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return MinAsyncInternal(connection: connection, tableName: tableName, @@ -2036,7 +2111,8 @@ public static Task MinAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -2051,6 +2127,7 @@ public static Task MinAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public static Task MinAsync(this IDbConnection connection, string tableName, @@ -2060,7 +2137,8 @@ public static Task MinAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return MinAsyncInternal(connection: connection, tableName: tableName, @@ -2070,7 +2148,8 @@ public static Task MinAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -2085,6 +2164,7 @@ public static Task MinAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. internal static Task MinAsyncInternal(this IDbConnection connection, string tableName, @@ -2094,7 +2174,8 @@ internal static Task MinAsyncInternal(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { // Variables var request = new MinRequest(tableName, @@ -2118,7 +2199,8 @@ internal static Task MinAsyncInternal(this IDbConnection connection, param: param, commandTimeout: commandTimeout, transaction: transaction, - trace: trace); + trace: trace, + cancellationToken: cancellationToken); } /// @@ -2134,6 +2216,7 @@ internal static Task MinAsyncInternal(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public static Task MinAsync(this IDbConnection connection, string tableName, @@ -2143,7 +2226,8 @@ public static Task MinAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return MinAsyncInternal(connection: connection, tableName: tableName, @@ -2153,7 +2237,8 @@ public static Task MinAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -2169,6 +2254,7 @@ public static Task MinAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public static Task MinAsync(this IDbConnection connection, string tableName, @@ -2178,7 +2264,8 @@ public static Task MinAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return MinAsyncInternal(connection: connection, tableName: tableName, @@ -2188,7 +2275,8 @@ public static Task MinAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -2204,6 +2292,7 @@ public static Task MinAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public static Task MinAsync(this IDbConnection connection, string tableName, @@ -2213,7 +2302,8 @@ public static Task MinAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return MinAsyncInternal(connection: connection, tableName: tableName, @@ -2223,7 +2313,8 @@ public static Task MinAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -2239,6 +2330,7 @@ public static Task MinAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public static Task MinAsync(this IDbConnection connection, string tableName, @@ -2248,7 +2340,8 @@ public static Task MinAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return MinAsyncInternal(connection: connection, tableName: tableName, @@ -2258,7 +2351,8 @@ public static Task MinAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -2274,6 +2368,7 @@ public static Task MinAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. internal static Task MinAsyncInternal(this IDbConnection connection, string tableName, @@ -2283,7 +2378,8 @@ internal static Task MinAsyncInternal(this IDbConnection conne int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { // Variables var request = new MinRequest(tableName, @@ -2307,7 +2403,8 @@ internal static Task MinAsyncInternal(this IDbConnection conne param: param, commandTimeout: commandTimeout, transaction: transaction, - trace: trace); + trace: trace, + cancellationToken: cancellationToken); } #endregion @@ -2392,13 +2489,15 @@ internal static TResult MinInternalBase(this IDbConnection connection, /// The command timeout in seconds to be used. /// The transaction to be used. /// The trace object to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. internal static async Task MinAsyncInternalBase(this IDbConnection connection, MinRequest request, object param, int? commandTimeout = null, IDbTransaction transaction = null, - ITrace trace = null) + ITrace trace = null, + CancellationToken cancellationToken = default) { // Variables var commandType = CommandType.Text; @@ -2433,8 +2532,9 @@ internal static async Task MinAsyncInternalBase(this IDbConnec commandType: commandType, commandTimeout: commandTimeout, transaction: transaction, + cancellationToken: cancellationToken, entityType: request.Type, - dbFields: await DbFieldCache.GetAsync(connection, request.Name, transaction, true), + dbFields: await DbFieldCache.GetAsync(connection, request.Name, transaction, true, cancellationToken), skipCommandArrayParametersCheck: true); // After Execution diff --git a/RepoDb.Core/RepoDb/Operations/DbConnection/MinAll.cs b/RepoDb.Core/RepoDb/Operations/DbConnection/MinAll.cs index b898caa83..965d1d723 100644 --- a/RepoDb.Core/RepoDb/Operations/DbConnection/MinAll.cs +++ b/RepoDb.Core/RepoDb/Operations/DbConnection/MinAll.cs @@ -5,6 +5,7 @@ using System.Data; using System.Linq; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -193,6 +194,7 @@ internal static TResult MinAllInternal(this IDbConnection conn /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public static Task MinAllAsync(this IDbConnection connection, Field field, @@ -200,7 +202,8 @@ public static Task MinAllAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MinAllAsyncInternal(connection: connection, @@ -209,7 +212,8 @@ public static Task MinAllAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -223,6 +227,7 @@ public static Task MinAllAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public static Task MinAllAsync(this IDbConnection connection, Expression> field, @@ -230,7 +235,8 @@ public static Task MinAllAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MinAllAsyncInternal(connection: connection, @@ -239,7 +245,8 @@ public static Task MinAllAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -254,6 +261,7 @@ public static Task MinAllAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public static Task MinAllAsync(this IDbConnection connection, Field field, @@ -261,7 +269,8 @@ public static Task MinAllAsync(this IDbConnection con int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MinAllAsyncInternal(connection: connection, @@ -270,7 +279,8 @@ public static Task MinAllAsync(this IDbConnection con commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -285,6 +295,7 @@ public static Task MinAllAsync(this IDbConnection con /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public static Task MinAllAsync(this IDbConnection connection, Expression> field, @@ -292,7 +303,8 @@ public static Task MinAllAsync(this IDbConnection con int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return MinAllAsyncInternal(connection: connection, @@ -301,7 +313,8 @@ public static Task MinAllAsync(this IDbConnection con commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -316,6 +329,7 @@ public static Task MinAllAsync(this IDbConnection con /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. internal static Task MinAllAsyncInternal(this IDbConnection connection, Field field, @@ -323,7 +337,8 @@ internal static Task MinAllAsyncInternal(this IDbConn int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { // Variables @@ -341,7 +356,8 @@ internal static Task MinAllAsyncInternal(this IDbConn param: param, commandTimeout: commandTimeout, transaction: transaction, - trace: trace); + trace: trace, + cancellationToken: cancellationToken); } #endregion @@ -465,6 +481,7 @@ internal static TResult MinAllInternal(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public static Task MinAllAsync(this IDbConnection connection, string tableName, @@ -473,7 +490,8 @@ public static Task MinAllAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return MinAllAsyncInternal(connection: connection, tableName: tableName, @@ -482,7 +500,8 @@ public static Task MinAllAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -497,6 +516,7 @@ public static Task MinAllAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public static Task MinAllAsync(this IDbConnection connection, string tableName, @@ -505,7 +525,8 @@ public static Task MinAllAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return MinAllAsyncInternal(connection: connection, tableName: tableName, @@ -514,7 +535,8 @@ public static Task MinAllAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -529,6 +551,7 @@ public static Task MinAllAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. internal static Task MinAllAsyncInternal(this IDbConnection connection, string tableName, @@ -537,7 +560,8 @@ internal static Task MinAllAsyncInternal(this IDbConnection co int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { // Variables var request = new MinAllRequest(tableName, @@ -553,7 +577,8 @@ internal static Task MinAllAsyncInternal(this IDbConnection co param: null, commandTimeout: commandTimeout, transaction: transaction, - trace: trace); + trace: trace, + cancellationToken: cancellationToken); } #endregion @@ -640,13 +665,15 @@ internal static TResult MinAllInternalBase(this IDbConnection connectio /// The command timeout in seconds to be used. /// The transaction to be used. /// The trace object to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. internal static async Task MinAllAsyncInternalBase(this IDbConnection connection, MinAllRequest request, object param, int? commandTimeout = null, IDbTransaction transaction = null, - ITrace trace = null) + ITrace trace = null, + CancellationToken cancellationToken = default) { // Variables var commandType = CommandType.Text; @@ -681,8 +708,9 @@ internal static async Task MinAllAsyncInternalBase(this IDbCon commandType: commandType, commandTimeout: commandTimeout, transaction: transaction, + cancellationToken: cancellationToken, entityType: request.Type, - dbFields: await DbFieldCache.GetAsync(connection, request.Name, transaction, true), + dbFields: await DbFieldCache.GetAsync(connection, request.Name, transaction, true, cancellationToken), skipCommandArrayParametersCheck: true); // After Execution diff --git a/RepoDb.Core/RepoDb/Operations/DbConnection/Query.cs b/RepoDb.Core/RepoDb/Operations/DbConnection/Query.cs index 2b3467755..aa135e483 100644 --- a/RepoDb.Core/RepoDb/Operations/DbConnection/Query.cs +++ b/RepoDb.Core/RepoDb/Operations/DbConnection/Query.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Data; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -738,6 +739,7 @@ internal static IEnumerable QueryInternal(this IDbConnection c /// The cache object to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public static async Task> QueryAsync(this IDbConnection connection, string tableName, @@ -752,13 +754,14 @@ public static async Task> QueryAsync(this IDbConne IDbTransaction transaction = null, ICache cache = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return await QueryAsyncInternal(connection: connection, tableName: tableName, fields: fields, - where: await WhatToQueryGroupAsync(connection, what, transaction), + where: await WhatToQueryGroupAsync(connection, what, transaction, cancellationToken), orderBy: orderBy, top: top, hints: hints, @@ -768,7 +771,8 @@ public static async Task> QueryAsync(this IDbConne transaction: transaction, cache: cache, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -793,6 +797,7 @@ public static async Task> QueryAsync(this IDbConne /// The cache object to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public static async Task> QueryAsync(this IDbConnection connection, string tableName, @@ -807,13 +812,14 @@ public static async Task> QueryAsync(this I IDbTransaction transaction = null, ICache cache = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return await QueryAsyncInternal(connection: connection, tableName: tableName, fields: fields, - where: await WhatToQueryGroupAsync(connection, what, transaction), + where: await WhatToQueryGroupAsync(connection, what, transaction, cancellationToken), orderBy: orderBy, top: top, hints: hints, @@ -823,7 +829,8 @@ public static async Task> QueryAsync(this I transaction: transaction, cache: cache, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -847,6 +854,7 @@ public static async Task> QueryAsync(this I /// The cache object to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public static async Task> QueryAsync(this IDbConnection connection, string tableName, @@ -861,7 +869,8 @@ public static async Task> QueryAsync(this IDbConne IDbTransaction transaction = null, ICache cache = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return await QueryAsyncInternal(connection: connection, @@ -877,7 +886,8 @@ public static async Task> QueryAsync(this IDbConne transaction: transaction, cache: cache, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -901,6 +911,7 @@ public static async Task> QueryAsync(this IDbConne /// The cache object to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public static async Task> QueryAsync(this IDbConnection connection, string tableName, @@ -915,7 +926,8 @@ public static async Task> QueryAsync(this IDbConne IDbTransaction transaction = null, ICache cache = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return await QueryAsyncInternal(connection: connection, @@ -931,7 +943,8 @@ public static async Task> QueryAsync(this IDbConne transaction: transaction, cache: cache, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -955,6 +968,7 @@ public static async Task> QueryAsync(this IDbConne /// The cache object to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public static async Task> QueryAsync(this IDbConnection connection, string tableName, @@ -969,7 +983,8 @@ public static async Task> QueryAsync(this IDbConne IDbTransaction transaction = null, ICache cache = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return await QueryAsyncInternal(connection: connection, @@ -985,7 +1000,8 @@ public static async Task> QueryAsync(this IDbConne transaction: transaction, cache: cache, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1009,6 +1025,7 @@ public static async Task> QueryAsync(this IDbConne /// The cache object to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public static async Task> QueryAsync(this IDbConnection connection, string tableName, @@ -1023,7 +1040,8 @@ public static async Task> QueryAsync(this IDbConne IDbTransaction transaction = null, ICache cache = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return await QueryAsyncInternal(connection: connection, @@ -1039,7 +1057,8 @@ public static async Task> QueryAsync(this IDbConne transaction: transaction, cache: cache, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1062,6 +1081,7 @@ public static async Task> QueryAsync(this IDbConne /// The cache object to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public static async Task> QueryAsync(this IDbConnection connection, object what, @@ -1075,12 +1095,13 @@ public static async Task> QueryAsync(this IDbConne IDbTransaction transaction = null, ICache cache = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return await QueryAsyncInternal(connection: connection, tableName: ClassMappedNameCache.Get(), - where: await WhatToQueryGroupAsync(connection, what, transaction), + where: await WhatToQueryGroupAsync(connection, what, transaction, cancellationToken), fields: fields, orderBy: orderBy, top: top, @@ -1091,7 +1112,8 @@ public static async Task> QueryAsync(this IDbConne transaction: transaction, cache: cache, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1115,6 +1137,7 @@ public static async Task> QueryAsync(this IDbConne /// The cache object to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public static async Task> QueryAsync(this IDbConnection connection, TWhat what, @@ -1128,12 +1151,13 @@ public static async Task> QueryAsync(this I IDbTransaction transaction = null, ICache cache = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return await QueryAsyncInternal(connection: connection, tableName: ClassMappedNameCache.Get(), - where: await WhatToQueryGroupAsync(connection, what, transaction), + where: await WhatToQueryGroupAsync(connection, what, transaction, cancellationToken), fields: fields, orderBy: orderBy, top: top, @@ -1144,7 +1168,8 @@ public static async Task> QueryAsync(this I transaction: transaction, cache: cache, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1167,6 +1192,7 @@ public static async Task> QueryAsync(this I /// The cache object to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public static Task> QueryAsync(this IDbConnection connection, QueryField where, @@ -1180,7 +1206,8 @@ public static Task> QueryAsync(this IDbConnection IDbTransaction transaction = null, ICache cache = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return QueryAsyncInternal(connection: connection, @@ -1196,7 +1223,8 @@ public static Task> QueryAsync(this IDbConnection transaction: transaction, cache: cache, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1219,6 +1247,7 @@ public static Task> QueryAsync(this IDbConnection /// The cache object to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public static Task> QueryAsync(this IDbConnection connection, IEnumerable where, @@ -1232,7 +1261,8 @@ public static Task> QueryAsync(this IDbConnection IDbTransaction transaction = null, ICache cache = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return QueryAsyncInternal(connection: connection, @@ -1248,7 +1278,8 @@ public static Task> QueryAsync(this IDbConnection transaction: transaction, cache: cache, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1271,6 +1302,7 @@ public static Task> QueryAsync(this IDbConnection /// The cache object to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public static Task> QueryAsync(this IDbConnection connection, Expression> where, @@ -1284,7 +1316,9 @@ public static Task> QueryAsync(this IDbConnection IDbTransaction transaction = null, ICache cache = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) where TEntity : class + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) + where TEntity : class { return QueryAsyncInternal(connection: connection, tableName: ClassMappedNameCache.Get(), @@ -1299,7 +1333,8 @@ public static Task> QueryAsync(this IDbConnection transaction: transaction, cache: cache, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1322,6 +1357,7 @@ public static Task> QueryAsync(this IDbConnection /// The cache object to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public static Task> QueryAsync(this IDbConnection connection, QueryGroup where, @@ -1335,7 +1371,8 @@ public static Task> QueryAsync(this IDbConnection IDbTransaction transaction = null, ICache cache = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return QueryAsyncInternal(connection: connection, @@ -1351,7 +1388,8 @@ public static Task> QueryAsync(this IDbConnection transaction: transaction, cache: cache, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1375,6 +1413,7 @@ public static Task> QueryAsync(this IDbConnection /// The cache object to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. internal static async Task> QueryAsyncInternal(this IDbConnection connection, string tableName, @@ -1389,12 +1428,13 @@ internal static async Task> QueryAsyncInternal(thi IDbTransaction transaction = null, ICache cache = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { // Ensure the fields fields = GetQualifiedFields(fields) ?? - (await DbFieldCache.GetAsync(connection, tableName, transaction))?.AsFields(); + (await DbFieldCache.GetAsync(connection, tableName, transaction, cancellationToken))?.AsFields(); // Return return await QueryAsyncInternalBase(connection: connection, @@ -1410,7 +1450,8 @@ internal static async Task> QueryAsyncInternal(thi transaction: transaction, cache: cache, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } #endregion @@ -1755,6 +1796,7 @@ internal static IEnumerable QueryInternal(this IDbConnection connection /// The cache object to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of dynamic objects. public static async Task> QueryAsync(this IDbConnection connection, string tableName, @@ -1769,11 +1811,12 @@ public static async Task> QueryAsync(this IDbConnect IDbTransaction transaction = null, ICache cache = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return await QueryAsync(connection: connection, tableName: tableName, - where: await WhatToQueryGroupAsync(connection, tableName, what, transaction), + where: await WhatToQueryGroupAsync(connection, tableName, what, transaction, cancellationToken), fields: fields, orderBy: orderBy, top: top, @@ -1784,7 +1827,8 @@ public static async Task> QueryAsync(this IDbConnect transaction: transaction, cache: cache, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1807,6 +1851,7 @@ public static async Task> QueryAsync(this IDbConnect /// The cache object to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of dynamic objects. public static async Task> QueryAsync(this IDbConnection connection, string tableName, @@ -1821,11 +1866,12 @@ public static async Task> QueryAsync(this IDbConnection con IDbTransaction transaction = null, ICache cache = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return await QueryAsync(connection: connection, tableName: tableName, - where: await WhatToQueryGroupAsync(connection, tableName, what, transaction), + where: await WhatToQueryGroupAsync(connection, tableName, what, transaction, cancellationToken), fields: fields, orderBy: orderBy, top: top, @@ -1836,7 +1882,8 @@ public static async Task> QueryAsync(this IDbConnection con transaction: transaction, cache: cache, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1859,6 +1906,7 @@ public static async Task> QueryAsync(this IDbConnection con /// The cache object to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of dynamic objects. public static Task> QueryAsync(this IDbConnection connection, string tableName, @@ -1873,7 +1921,8 @@ public static Task> QueryAsync(this IDbConnection connectio IDbTransaction transaction = null, ICache cache = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return QueryAsync(connection: connection, tableName: tableName, @@ -1888,7 +1937,8 @@ public static Task> QueryAsync(this IDbConnection connectio transaction: transaction, cache: cache, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1911,6 +1961,7 @@ public static Task> QueryAsync(this IDbConnection connectio /// The cache object to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of dynamic objects. public static Task> QueryAsync(this IDbConnection connection, string tableName, @@ -1925,7 +1976,8 @@ public static Task> QueryAsync(this IDbConnection connectio IDbTransaction transaction = null, ICache cache = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return QueryAsync(connection: connection, tableName: tableName, @@ -1940,7 +1992,8 @@ public static Task> QueryAsync(this IDbConnection connectio transaction: transaction, cache: cache, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1963,6 +2016,7 @@ public static Task> QueryAsync(this IDbConnection connectio /// The cache object to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of dynamic objects. public static Task> QueryAsync(this IDbConnection connection, string tableName, @@ -1977,7 +2031,8 @@ public static Task> QueryAsync(this IDbConnection connectio IDbTransaction transaction = null, ICache cache = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return QueryAsyncInternal(connection: connection, tableName: tableName, @@ -1992,7 +2047,8 @@ public static Task> QueryAsync(this IDbConnection connectio transaction: transaction, cache: cache, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -2015,6 +2071,7 @@ public static Task> QueryAsync(this IDbConnection connectio /// The cache object to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of dynamic objects. internal static Task> QueryAsyncInternal(this IDbConnection connection, string tableName, @@ -2029,7 +2086,8 @@ internal static Task> QueryAsyncInternal(this IDbConnection IDbTransaction transaction = null, ICache cache = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return QueryAsyncInternal(connection: connection, tableName: tableName, @@ -2044,7 +2102,8 @@ internal static Task> QueryAsyncInternal(this IDbConnection transaction: transaction, cache: cache, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } #endregion @@ -2196,6 +2255,7 @@ internal static IEnumerable QueryInternalBase(this IDbConnecti /// The cache object to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. internal static async Task> QueryAsyncInternalBase(this IDbConnection connection, string tableName, @@ -2210,7 +2270,8 @@ internal static async Task> QueryAsyncInternalBase IDbTransaction transaction = null, ICache cache = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { // Get Cache @@ -2272,6 +2333,7 @@ internal static async Task> QueryAsyncInternalBase cacheItemExpiration: null, commandTimeout: commandTimeout, transaction: transaction, + cancellationToken: cancellationToken, cache: null, tableName: tableName, skipCommandArrayParametersCheck: true); diff --git a/RepoDb.Core/RepoDb/Operations/DbConnection/QueryAll.cs b/RepoDb.Core/RepoDb/Operations/DbConnection/QueryAll.cs index 1436cfe06..e65207a6b 100644 --- a/RepoDb.Core/RepoDb/Operations/DbConnection/QueryAll.cs +++ b/RepoDb.Core/RepoDb/Operations/DbConnection/QueryAll.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Data; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -186,6 +187,7 @@ internal static IEnumerable QueryAllInternal(this IDbConnectio /// The cache object to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public static Task> QueryAllAsync(this IDbConnection connection, string tableName, @@ -198,7 +200,8 @@ public static Task> QueryAllAsync(this IDbConnecti IDbTransaction transaction = null, ICache cache = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return QueryAllAsyncInternal(connection: connection, @@ -212,7 +215,8 @@ public static Task> QueryAllAsync(this IDbConnecti transaction: transaction, cache: cache, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -233,6 +237,7 @@ public static Task> QueryAllAsync(this IDbConnecti /// The cache object to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public static Task> QueryAllAsync(this IDbConnection connection, IEnumerable fields = null, @@ -244,7 +249,8 @@ public static Task> QueryAllAsync(this IDbConnecti IDbTransaction transaction = null, ICache cache = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return QueryAllAsyncInternal(connection: connection, @@ -258,7 +264,8 @@ public static Task> QueryAllAsync(this IDbConnecti transaction: transaction, cache: cache, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -280,6 +287,7 @@ public static Task> QueryAllAsync(this IDbConnecti /// The cache object to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. internal static async Task> QueryAllAsyncInternal(this IDbConnection connection, string tableName, @@ -292,12 +300,13 @@ internal static async Task> QueryAllAsyncInternal( IDbTransaction transaction = null, ICache cache = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { // Ensure the fields fields = GetQualifiedFields(fields) ?? - (await DbFieldCache.GetAsync(connection, tableName, transaction))?.AsFields(); + (await DbFieldCache.GetAsync(connection, tableName, transaction, cancellationToken))?.AsFields(); // Return return await QueryAllAsyncInternalBase(connection: connection, @@ -311,7 +320,8 @@ internal static async Task> QueryAllAsyncInternal( transaction: transaction, cache: cache, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } #endregion @@ -432,6 +442,7 @@ internal static IEnumerable QueryAllInternal(this IDbConnection connect /// The cache object to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public static Task> QueryAllAsync(this IDbConnection connection, string tableName, @@ -444,7 +455,8 @@ public static Task> QueryAllAsync(this IDbConnection connec IDbTransaction transaction = null, ICache cache = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return QueryAllAsyncInternal(connection: connection, tableName: tableName, @@ -457,7 +469,8 @@ public static Task> QueryAllAsync(this IDbConnection connec transaction: transaction, cache: cache, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -478,6 +491,7 @@ public static Task> QueryAllAsync(this IDbConnection connec /// The cache object to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. internal static Task> QueryAllAsyncInternal(this IDbConnection connection, string tableName, @@ -490,7 +504,8 @@ internal static Task> QueryAllAsyncInternal(this IDbConnect IDbTransaction transaction = null, ICache cache = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return QueryAllAsyncInternal(connection: connection, tableName: tableName, @@ -503,7 +518,8 @@ internal static Task> QueryAllAsyncInternal(this IDbConnect transaction: transaction, cache: cache, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } #endregion @@ -641,6 +657,7 @@ internal static IEnumerable QueryAllInternalBase(this IDbConne /// The cache object to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. internal static async Task> QueryAllAsyncInternalBase(this IDbConnection connection, string tableName, @@ -653,7 +670,8 @@ internal static async Task> QueryAllAsyncInternalBase> QueryAllAsyncInternalBase, IEnumerable> QueryMultipleInternal, IEnumerable>)null; - using (var reader = ExecuteReaderInternal(connection: connection, + using (var reader = (DbDataReader)ExecuteReaderInternal(connection: connection, commandText: commandText, param: param, commandType: commandType, @@ -186,12 +187,12 @@ internal static Tuple, IEnumerable> QueryMultipleInternal(), transaction); - var item1 = DataReader.ToEnumerable((DbDataReader)reader, dbFields, dbSetting)?.AsList(); + var item1 = DataReader.ToEnumerable(reader, dbFields, dbSetting)?.AsList(); // T2 reader?.NextResult(); dbFields = DbFieldCache.Get(connection, ClassMappedNameCache.Get(), transaction); - var item2 = DataReader.ToEnumerable((DbDataReader)reader, dbFields, dbSetting)?.AsList(); + var item2 = DataReader.ToEnumerable(reader, dbFields, dbSetting)?.AsList(); // Result result = new Tuple, IEnumerable>(item1, item2); @@ -400,7 +401,7 @@ internal static Tuple, IEnumerable, IEnumerable> QueryMu // Actual Execution var result = (Tuple, IEnumerable, IEnumerable>)null; - using (var reader = ExecuteReaderInternal(connection: connection, + using (var reader = (DbDataReader)ExecuteReaderInternal(connection: connection, commandText: commandText, param: param, commandType: commandType, @@ -415,17 +416,17 @@ internal static Tuple, IEnumerable, IEnumerable> QueryMu // T1 dbFields = DbFieldCache.Get(connection, ClassMappedNameCache.Get(), transaction); - var item1 = DataReader.ToEnumerable((DbDataReader)reader, dbFields, dbSetting)?.AsList(); + var item1 = DataReader.ToEnumerable(reader, dbFields, dbSetting)?.AsList(); // T2 reader?.NextResult(); dbFields = DbFieldCache.Get(connection, ClassMappedNameCache.Get(), transaction); - var item2 = DataReader.ToEnumerable((DbDataReader)reader, dbFields, dbSetting)?.AsList(); + var item2 = DataReader.ToEnumerable(reader, dbFields, dbSetting)?.AsList(); // T3 reader?.NextResult(); dbFields = DbFieldCache.Get(connection, ClassMappedNameCache.Get(), transaction); - var item3 = DataReader.ToEnumerable((DbDataReader)reader, dbFields, dbSetting)?.AsList(); + var item3 = DataReader.ToEnumerable(reader, dbFields, dbSetting)?.AsList(); // Result result = new Tuple, IEnumerable, IEnumerable>(item1, item2, item3); @@ -674,7 +675,7 @@ internal static Tuple, IEnumerable, IEnumerable, IEnumer // Actual Execution var result = (Tuple, IEnumerable, IEnumerable, IEnumerable>)null; - using (var reader = ExecuteReaderInternal(connection: connection, + using (var reader = (DbDataReader)ExecuteReaderInternal(connection: connection, commandText: commandText, param: param, commandType: commandType, @@ -689,22 +690,22 @@ internal static Tuple, IEnumerable, IEnumerable, IEnumer // T1 dbFields = DbFieldCache.Get(connection, ClassMappedNameCache.Get(), transaction); - var item1 = DataReader.ToEnumerable((DbDataReader)reader, dbFields, dbSetting)?.AsList(); + var item1 = DataReader.ToEnumerable(reader, dbFields, dbSetting)?.AsList(); // T2 reader?.NextResult(); dbFields = DbFieldCache.Get(connection, ClassMappedNameCache.Get(), transaction); - var item2 = DataReader.ToEnumerable((DbDataReader)reader, dbFields, dbSetting)?.AsList(); + var item2 = DataReader.ToEnumerable(reader, dbFields, dbSetting)?.AsList(); // T3 reader?.NextResult(); dbFields = DbFieldCache.Get(connection, ClassMappedNameCache.Get(), transaction); - var item3 = DataReader.ToEnumerable((DbDataReader)reader, dbFields, dbSetting)?.AsList(); + var item3 = DataReader.ToEnumerable(reader, dbFields, dbSetting)?.AsList(); // T4 reader?.NextResult(); dbFields = DbFieldCache.Get(connection, ClassMappedNameCache.Get(), transaction); - var item4 = DataReader.ToEnumerable((DbDataReader)reader, dbFields, dbSetting)?.AsList(); + var item4 = DataReader.ToEnumerable(reader, dbFields, dbSetting)?.AsList(); // Result result = new Tuple, IEnumerable, IEnumerable, IEnumerable>(item1, item2, item3, item4); @@ -991,7 +992,7 @@ internal static Tuple, IEnumerable, IEnumerable, IEnumer // Actual Execution var result = (Tuple, IEnumerable, IEnumerable, IEnumerable, IEnumerable>)null; - using (var reader = ExecuteReaderInternal(connection: connection, + using (var reader = (DbDataReader)ExecuteReaderInternal(connection: connection, commandText: commandText, param: param, commandType: commandType, @@ -1006,27 +1007,27 @@ internal static Tuple, IEnumerable, IEnumerable, IEnumer // T1 dbFields = DbFieldCache.Get(connection, ClassMappedNameCache.Get(), transaction); - var item1 = DataReader.ToEnumerable((DbDataReader)reader, dbFields, dbSetting)?.AsList(); + var item1 = DataReader.ToEnumerable(reader, dbFields, dbSetting)?.AsList(); // T2 reader?.NextResult(); dbFields = DbFieldCache.Get(connection, ClassMappedNameCache.Get(), transaction); - var item2 = DataReader.ToEnumerable((DbDataReader)reader, dbFields, dbSetting)?.AsList(); + var item2 = DataReader.ToEnumerable(reader, dbFields, dbSetting)?.AsList(); // T3 reader?.NextResult(); dbFields = DbFieldCache.Get(connection, ClassMappedNameCache.Get(), transaction); - var item3 = DataReader.ToEnumerable((DbDataReader)reader, dbFields, dbSetting)?.AsList(); + var item3 = DataReader.ToEnumerable(reader, dbFields, dbSetting)?.AsList(); // T4 reader?.NextResult(); dbFields = DbFieldCache.Get(connection, ClassMappedNameCache.Get(), transaction); - var item4 = DataReader.ToEnumerable((DbDataReader)reader, dbFields, dbSetting)?.AsList(); + var item4 = DataReader.ToEnumerable(reader, dbFields, dbSetting)?.AsList(); // T5 reader?.NextResult(); dbFields = DbFieldCache.Get(connection, ClassMappedNameCache.Get(), transaction); - var item5 = DataReader.ToEnumerable((DbDataReader)reader, dbFields, dbSetting)?.AsList(); + var item5 = DataReader.ToEnumerable(reader, dbFields, dbSetting)?.AsList(); // Result result = new Tuple, IEnumerable, IEnumerable, IEnumerable, IEnumerable>(item1, item2, item3, item4, item5); @@ -1351,7 +1352,7 @@ internal static Tuple, IEnumerable, IEnumerable, IEnumer // Actual Execution var result = (Tuple, IEnumerable, IEnumerable, IEnumerable, IEnumerable, IEnumerable>)null; - using (var reader = ExecuteReaderInternal(connection: connection, + using (var reader = (DbDataReader)ExecuteReaderInternal(connection: connection, commandText: commandText, param: param, commandType: commandType, @@ -1366,32 +1367,32 @@ internal static Tuple, IEnumerable, IEnumerable, IEnumer // T1 dbFields = DbFieldCache.Get(connection, ClassMappedNameCache.Get(), transaction); - var item1 = DataReader.ToEnumerable((DbDataReader)reader, dbFields, dbSetting)?.AsList(); + var item1 = DataReader.ToEnumerable(reader, dbFields, dbSetting)?.AsList(); // T2 reader?.NextResult(); dbFields = DbFieldCache.Get(connection, ClassMappedNameCache.Get(), transaction); - var item2 = DataReader.ToEnumerable((DbDataReader)reader, dbFields, dbSetting)?.AsList(); + var item2 = DataReader.ToEnumerable(reader, dbFields, dbSetting)?.AsList(); // T3 reader?.NextResult(); dbFields = DbFieldCache.Get(connection, ClassMappedNameCache.Get(), transaction); - var item3 = DataReader.ToEnumerable((DbDataReader)reader, dbFields, dbSetting)?.AsList(); + var item3 = DataReader.ToEnumerable(reader, dbFields, dbSetting)?.AsList(); // T4 reader?.NextResult(); dbFields = DbFieldCache.Get(connection, ClassMappedNameCache.Get(), transaction); - var item4 = DataReader.ToEnumerable((DbDataReader)reader, dbFields, dbSetting)?.AsList(); + var item4 = DataReader.ToEnumerable(reader, dbFields, dbSetting)?.AsList(); // T5 reader?.NextResult(); dbFields = DbFieldCache.Get(connection, ClassMappedNameCache.Get(), transaction); - var item5 = DataReader.ToEnumerable((DbDataReader)reader, dbFields, dbSetting)?.AsList(); + var item5 = DataReader.ToEnumerable(reader, dbFields, dbSetting)?.AsList(); // T6 reader?.NextResult(); dbFields = DbFieldCache.Get(connection, ClassMappedNameCache.Get(), transaction); - var item6 = DataReader.ToEnumerable((DbDataReader)reader, dbFields, dbSetting)?.AsList(); + var item6 = DataReader.ToEnumerable(reader, dbFields, dbSetting)?.AsList(); // Result result = new Tuple, IEnumerable, IEnumerable, IEnumerable, IEnumerable, IEnumerable>( @@ -1755,7 +1756,7 @@ internal static Tuple, IEnumerable, IEnumerable, IEnumer // Actual Execution var result = (Tuple, IEnumerable, IEnumerable, IEnumerable, IEnumerable, IEnumerable, IEnumerable>)null; - using (var reader = ExecuteReaderInternal(connection: connection, + using (var reader = (DbDataReader)ExecuteReaderInternal(connection: connection, commandText: commandText, param: param, commandType: commandType, @@ -1770,37 +1771,37 @@ internal static Tuple, IEnumerable, IEnumerable, IEnumer // T1 dbFields = DbFieldCache.Get(connection, ClassMappedNameCache.Get(), transaction); - var item1 = DataReader.ToEnumerable((DbDataReader)reader, dbFields, dbSetting)?.AsList(); + var item1 = DataReader.ToEnumerable(reader, dbFields, dbSetting)?.AsList(); // T2 reader?.NextResult(); dbFields = DbFieldCache.Get(connection, ClassMappedNameCache.Get(), transaction); - var item2 = DataReader.ToEnumerable((DbDataReader)reader, dbFields, dbSetting)?.AsList(); + var item2 = DataReader.ToEnumerable(reader, dbFields, dbSetting)?.AsList(); // T3 reader?.NextResult(); dbFields = DbFieldCache.Get(connection, ClassMappedNameCache.Get(), transaction); - var item3 = DataReader.ToEnumerable((DbDataReader)reader, dbFields, dbSetting)?.AsList(); + var item3 = DataReader.ToEnumerable(reader, dbFields, dbSetting)?.AsList(); // T4 reader?.NextResult(); dbFields = DbFieldCache.Get(connection, ClassMappedNameCache.Get(), transaction); - var item4 = DataReader.ToEnumerable((DbDataReader)reader, dbFields, dbSetting)?.AsList(); + var item4 = DataReader.ToEnumerable(reader, dbFields, dbSetting)?.AsList(); // T5 reader?.NextResult(); dbFields = DbFieldCache.Get(connection, ClassMappedNameCache.Get(), transaction); - var item5 = DataReader.ToEnumerable((DbDataReader)reader, dbFields, dbSetting)?.AsList(); + var item5 = DataReader.ToEnumerable(reader, dbFields, dbSetting)?.AsList(); // T6 reader?.NextResult(); dbFields = DbFieldCache.Get(connection, ClassMappedNameCache.Get(), transaction); - var item6 = DataReader.ToEnumerable((DbDataReader)reader, dbFields, dbSetting)?.AsList(); + var item6 = DataReader.ToEnumerable(reader, dbFields, dbSetting)?.AsList(); // Extract the seventh result reader?.NextResult(); dbFields = DbFieldCache.Get(connection, ClassMappedNameCache.Get(), transaction); - var item7 = DataReader.ToEnumerable((DbDataReader)reader, dbFields, dbSetting)?.AsList(); + var item7 = DataReader.ToEnumerable(reader, dbFields, dbSetting)?.AsList(); // Result result = new Tuple, IEnumerable, IEnumerable, IEnumerable, IEnumerable, IEnumerable, IEnumerable>( @@ -1844,6 +1845,7 @@ internal static Tuple, IEnumerable, IEnumerable, IEnumer /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// A tuple of 2 enumerable target data entity types. public static Task, IEnumerable>> QueryMultipleAsync(this IDbConnection connection, Expression> where1, @@ -1857,7 +1859,8 @@ public static Task, IEnumerable>> QueryMultipleAsync, IEnumerable>> QueryMultipleAsync @@ -1894,6 +1898,7 @@ public static Task, IEnumerable>> QueryMultipleAsyncThe transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// A tuple of 2 enumerable target data entity types. internal static async Task, IEnumerable>> QueryMultipleAsyncInternal(this IDbConnection connection, QueryGroup where1, @@ -1907,7 +1912,8 @@ internal static async Task, IEnumerable>> QueryMultipl int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where T1 : class where T2 : class { @@ -1976,12 +1982,13 @@ internal static async Task, IEnumerable>> QueryMultipl // Actual Execution var result = (Tuple, IEnumerable>)null; - using (var reader = await ExecuteReaderAsyncInternal(connection: connection, + using (var reader = (DbDataReader)await ExecuteReaderAsyncInternal(connection: connection, commandText: commandText, param: param, commandType: commandType, commandTimeout: commandTimeout, transaction: transaction, + cancellationToken: cancellationToken, entityType: null, dbFields: null, skipCommandArrayParametersCheck: true)) @@ -1990,13 +1997,13 @@ internal static async Task, IEnumerable>> QueryMultipl var dbFields = (IEnumerable)null; // T1 - dbFields = await DbFieldCache.GetAsync(connection, ClassMappedNameCache.Get(), transaction); - var item1 = DataReader.ToEnumerable((DbDataReader)reader, dbFields, dbSetting)?.AsList(); + dbFields = await DbFieldCache.GetAsync(connection, ClassMappedNameCache.Get(), transaction, true, cancellationToken); + var item1 = await DataReader.ToEnumerableAsync(reader, dbFields, dbSetting, cancellationToken); // T2 - reader?.NextResult(); - dbFields = await DbFieldCache.GetAsync(connection, ClassMappedNameCache.Get(), transaction); - var item2 = DataReader.ToEnumerable((DbDataReader)reader, dbFields, dbSetting)?.AsList(); + await reader.NextResultAsync(cancellationToken); + dbFields = await DbFieldCache.GetAsync(connection, ClassMappedNameCache.Get(), transaction, true, cancellationToken); + var item2 = await DataReader.ToEnumerableAsync(reader, dbFields, dbSetting, cancellationToken); // Result result = new Tuple, IEnumerable>(item1, item2); @@ -2040,6 +2047,7 @@ internal static async Task, IEnumerable>> QueryMultipl /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// A tuple of 3 enumerable target data entity types. public static Task, IEnumerable, IEnumerable>> QueryMultipleAsync(this IDbConnection connection, Expression> where1, @@ -2057,7 +2065,8 @@ public static Task, IEnumerable, IEnumerable>> Que int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where T1 : class where T2 : class where T3 : class @@ -2078,7 +2087,8 @@ public static Task, IEnumerable, IEnumerable>> Que commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -2104,6 +2114,7 @@ public static Task, IEnumerable, IEnumerable>> Que /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// A tuple of 3 enumerable target data entity types. internal static async Task, IEnumerable, IEnumerable>> QueryMultipleAsyncInternal(this IDbConnection connection, QueryGroup where1, @@ -2121,7 +2132,8 @@ internal static async Task, IEnumerable, IEnumerable, IEnumerable, IEnumerable, IEnumerable, IEnumerable>)null; - using (var reader = await ExecuteReaderAsyncInternal(connection: connection, + using (var reader = (DbDataReader)await ExecuteReaderAsyncInternal(connection: connection, commandText: commandText, param: param, commandType: commandType, commandTimeout: commandTimeout, transaction: transaction, + cancellationToken: cancellationToken, entityType: null, dbFields: null, skipCommandArrayParametersCheck: true)) @@ -2219,18 +2232,18 @@ internal static async Task, IEnumerable, IEnumerable)null; // T1 - dbFields = await DbFieldCache.GetAsync(connection, ClassMappedNameCache.Get(), transaction); - var item1 = DataReader.ToEnumerable((DbDataReader)reader, dbFields, dbSetting)?.AsList(); + dbFields = await DbFieldCache.GetAsync(connection, ClassMappedNameCache.Get(), transaction, true, cancellationToken); + var item1 = await DataReader.ToEnumerableAsync(reader, dbFields, dbSetting, cancellationToken); // T2 - reader?.NextResult(); - dbFields = await DbFieldCache.GetAsync(connection, ClassMappedNameCache.Get(), transaction); - var item2 = DataReader.ToEnumerable((DbDataReader)reader, dbFields, dbSetting)?.AsList(); + await reader.NextResultAsync(cancellationToken); + dbFields = await DbFieldCache.GetAsync(connection, ClassMappedNameCache.Get(), transaction, true, cancellationToken); + var item2 = await DataReader.ToEnumerableAsync(reader, dbFields, dbSetting, cancellationToken); // T3 - reader?.NextResult(); - dbFields = await DbFieldCache.GetAsync(connection, ClassMappedNameCache.Get(), transaction); - var item3 = DataReader.ToEnumerable((DbDataReader)reader, dbFields, dbSetting)?.AsList(); + await reader.NextResultAsync(cancellationToken); + dbFields = await DbFieldCache.GetAsync(connection, ClassMappedNameCache.Get(), transaction, true, cancellationToken); + var item3 = await DataReader.ToEnumerableAsync(reader, dbFields, dbSetting, cancellationToken); // Result result = new Tuple, IEnumerable, IEnumerable>(item1, item2, item3); @@ -2279,6 +2292,7 @@ internal static async Task, IEnumerable, IEnumerableThe transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// A tuple of 4 enumerable target data entity types. public static Task, IEnumerable, IEnumerable, IEnumerable>> QueryMultipleAsync(this IDbConnection connection, @@ -2301,7 +2315,8 @@ public static Task, IEnumerable, IEnumerable, IEnu int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where T1 : class where T2 : class where T3 : class @@ -2327,7 +2342,8 @@ public static Task, IEnumerable, IEnumerable, IEnu commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -2358,6 +2374,7 @@ public static Task, IEnumerable, IEnumerable, IEnu /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// A tuple of 4 enumerable target data entity types. internal static async Task, IEnumerable, IEnumerable, IEnumerable>> QueryMultipleAsyncInternal(this IDbConnection connection, @@ -2380,7 +2397,8 @@ internal static async Task, IEnumerable, IEnumerable, IEnumerable, IEnumerable, IEnumerable, IEnumerable, IEnumerable>)null; - using (var reader = await ExecuteReaderAsyncInternal(connection: connection, + using (var reader = (DbDataReader)await ExecuteReaderAsyncInternal(connection: connection, commandText: commandText, param: param, commandType: commandType, commandTimeout: commandTimeout, transaction: transaction, + cancellationToken: cancellationToken, entityType: null, dbFields: null, skipCommandArrayParametersCheck: true)) @@ -2493,23 +2512,23 @@ internal static async Task, IEnumerable, IEnumerable)null; // T1 - dbFields = await DbFieldCache.GetAsync(connection, ClassMappedNameCache.Get(), transaction); - var item1 = DataReader.ToEnumerable((DbDataReader)reader, dbFields, dbSetting)?.AsList(); + dbFields = await DbFieldCache.GetAsync(connection, ClassMappedNameCache.Get(), transaction, true, cancellationToken); + var item1 = await DataReader.ToEnumerableAsync(reader, dbFields, dbSetting, cancellationToken); // T2 - reader?.NextResult(); - dbFields = await DbFieldCache.GetAsync(connection, ClassMappedNameCache.Get(), transaction); - var item2 = DataReader.ToEnumerable((DbDataReader)reader, dbFields, dbSetting)?.AsList(); + await reader.NextResultAsync(cancellationToken); + dbFields = await DbFieldCache.GetAsync(connection, ClassMappedNameCache.Get(), transaction, true, cancellationToken); + var item2 = await DataReader.ToEnumerableAsync(reader, dbFields, dbSetting, cancellationToken); // T3 - reader?.NextResult(); - dbFields = await DbFieldCache.GetAsync(connection, ClassMappedNameCache.Get(), transaction); - var item3 = DataReader.ToEnumerable((DbDataReader)reader, dbFields, dbSetting)?.AsList(); + await reader.NextResultAsync(cancellationToken); + dbFields = await DbFieldCache.GetAsync(connection, ClassMappedNameCache.Get(), transaction, true, cancellationToken); + var item3 = await DataReader.ToEnumerableAsync(reader, dbFields, dbSetting, cancellationToken); // T4 - reader?.NextResult(); - dbFields = await DbFieldCache.GetAsync(connection, ClassMappedNameCache.Get(), transaction); - var item4 = DataReader.ToEnumerable((DbDataReader)reader, dbFields, dbSetting)?.AsList(); + await reader.NextResultAsync(cancellationToken); + dbFields = await DbFieldCache.GetAsync(connection, ClassMappedNameCache.Get(), transaction, true, cancellationToken); + var item4 = await DataReader.ToEnumerableAsync(reader, dbFields, dbSetting, cancellationToken); // Result result = new Tuple, IEnumerable, IEnumerable, IEnumerable>(item1, item2, item3, item4); @@ -2563,6 +2582,7 @@ internal static async Task, IEnumerable, IEnumerableThe transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// A tuple of 5 enumerable target data entity types. public static Task, IEnumerable, IEnumerable, IEnumerable, IEnumerable>> QueryMultipleAsync(this IDbConnection connection, @@ -2589,7 +2609,8 @@ public static Task, IEnumerable, IEnumerable, IEnu int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where T1 : class where T2 : class where T3 : class @@ -2620,7 +2641,8 @@ public static Task, IEnumerable, IEnumerable, IEnu commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -2656,6 +2678,7 @@ public static Task, IEnumerable, IEnumerable, IEnu /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// A tuple of 5 enumerable target data entity types. internal static async Task, IEnumerable, IEnumerable, IEnumerable, IEnumerable>> QueryMultipleAsyncInternal(this IDbConnection connection, @@ -2682,7 +2705,8 @@ internal static async Task, IEnumerable, IEnumerable, IEnumerable, IEnumerable, IEnumerable, IEnumerable, IEnumerable, IEnumerable>)null; - using (var reader = await ExecuteReaderAsyncInternal(connection: connection, + using (var reader = (DbDataReader)await ExecuteReaderAsyncInternal(connection: connection, commandText: commandText, param: param, commandType: commandType, commandTimeout: commandTimeout, transaction: transaction, + cancellationToken: cancellationToken, entityType: null, dbFields: null, skipCommandArrayParametersCheck: true)) @@ -2810,28 +2835,28 @@ internal static async Task, IEnumerable, IEnumerable)null; // T1 - dbFields = await DbFieldCache.GetAsync(connection, ClassMappedNameCache.Get(), transaction); - var item1 = DataReader.ToEnumerable((DbDataReader)reader, dbFields, dbSetting)?.AsList(); + dbFields = await DbFieldCache.GetAsync(connection, ClassMappedNameCache.Get(), transaction, true, cancellationToken); + var item1 = await DataReader.ToEnumerableAsync(reader, dbFields, dbSetting, cancellationToken); // T2 - reader?.NextResult(); - dbFields = await DbFieldCache.GetAsync(connection, ClassMappedNameCache.Get(), transaction); - var item2 = DataReader.ToEnumerable((DbDataReader)reader, dbFields, dbSetting)?.AsList(); + await reader.NextResultAsync(cancellationToken); + dbFields = await DbFieldCache.GetAsync(connection, ClassMappedNameCache.Get(), transaction, true, cancellationToken); + var item2 = await DataReader.ToEnumerableAsync(reader, dbFields, dbSetting, cancellationToken); // T3 - reader?.NextResult(); - dbFields = await DbFieldCache.GetAsync(connection, ClassMappedNameCache.Get(), transaction); - var item3 = DataReader.ToEnumerable((DbDataReader)reader, dbFields, dbSetting)?.AsList(); + await reader.NextResultAsync(cancellationToken); + dbFields = await DbFieldCache.GetAsync(connection, ClassMappedNameCache.Get(), transaction, true, cancellationToken); + var item3 = await DataReader.ToEnumerableAsync(reader, dbFields, dbSetting, cancellationToken); // T4 - reader?.NextResult(); - dbFields = await DbFieldCache.GetAsync(connection, ClassMappedNameCache.Get(), transaction); - var item4 = DataReader.ToEnumerable((DbDataReader)reader, dbFields, dbSetting)?.AsList(); + await reader.NextResultAsync(cancellationToken); + dbFields = await DbFieldCache.GetAsync(connection, ClassMappedNameCache.Get(), transaction, true, cancellationToken); + var item4 = await DataReader.ToEnumerableAsync(reader, dbFields, dbSetting, cancellationToken); // T5 - reader?.NextResult(); - dbFields = await DbFieldCache.GetAsync(connection, ClassMappedNameCache.Get(), transaction); - var item5 = DataReader.ToEnumerable((DbDataReader)reader, dbFields, dbSetting)?.AsList(); + await reader.NextResultAsync(cancellationToken); + dbFields = await DbFieldCache.GetAsync(connection, ClassMappedNameCache.Get(), transaction, true, cancellationToken); + var item5 = await DataReader.ToEnumerableAsync(reader, dbFields, dbSetting, cancellationToken); // Result result = new Tuple, IEnumerable, IEnumerable, IEnumerable, IEnumerable>(item1, item2, item3, item4, item5); @@ -2890,6 +2915,7 @@ internal static async Task, IEnumerable, IEnumerableThe transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// A tuple of 6 enumerable target data entity types. public static Task, IEnumerable, IEnumerable, IEnumerable, IEnumerable, IEnumerable>> QueryMultipleAsync(this IDbConnection connection, @@ -2920,7 +2946,8 @@ public static Task, IEnumerable, IEnumerable, IEnu int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where T1 : class where T2 : class where T3 : class @@ -2956,7 +2983,8 @@ public static Task, IEnumerable, IEnumerable, IEnu commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -2997,6 +3025,7 @@ public static Task, IEnumerable, IEnumerable, IEnu /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// A tuple of 6 enumerable target data entity types. internal static async Task, IEnumerable, IEnumerable, IEnumerable, IEnumerable, IEnumerable>> QueryMultipleAsyncInternal(this IDbConnection connection, @@ -3027,7 +3056,8 @@ internal static async Task, IEnumerable, IEnumerable, IEnumerable, IEnumerable, IEnumerable, IEnumerable, IEnumerable, IEnumerable, IEnumerable>)null; - using (var reader = await ExecuteReaderAsyncInternal(connection: connection, + using (var reader = (DbDataReader)await ExecuteReaderAsyncInternal(connection: connection, commandText: commandText, param: param, commandType: commandType, commandTimeout: commandTimeout, transaction: transaction, + cancellationToken: cancellationToken, entityType: null, dbFields: null, skipCommandArrayParametersCheck: true)) @@ -3170,33 +3201,33 @@ internal static async Task, IEnumerable, IEnumerable)null; // T1 - dbFields = await DbFieldCache.GetAsync(connection, ClassMappedNameCache.Get(), transaction); - var item1 = DataReader.ToEnumerable((DbDataReader)reader, dbFields, dbSetting)?.AsList(); + dbFields = await DbFieldCache.GetAsync(connection, ClassMappedNameCache.Get(), transaction, true, cancellationToken); + var item1 = await DataReader.ToEnumerableAsync(reader, dbFields, dbSetting, cancellationToken); // T2 - reader?.NextResult(); - dbFields = await DbFieldCache.GetAsync(connection, ClassMappedNameCache.Get(), transaction); - var item2 = DataReader.ToEnumerable((DbDataReader)reader, dbFields, dbSetting)?.AsList(); + await reader.NextResultAsync(cancellationToken); + dbFields = await DbFieldCache.GetAsync(connection, ClassMappedNameCache.Get(), transaction, true, cancellationToken); + var item2 = await DataReader.ToEnumerableAsync(reader, dbFields, dbSetting, cancellationToken); // T3 - reader?.NextResult(); - dbFields = await DbFieldCache.GetAsync(connection, ClassMappedNameCache.Get(), transaction); - var item3 = DataReader.ToEnumerable((DbDataReader)reader, dbFields, dbSetting)?.AsList(); + await reader.NextResultAsync(cancellationToken); + dbFields = await DbFieldCache.GetAsync(connection, ClassMappedNameCache.Get(), transaction, true, cancellationToken); + var item3 = await DataReader.ToEnumerableAsync(reader, dbFields, dbSetting, cancellationToken); // T4 - reader?.NextResult(); - dbFields = await DbFieldCache.GetAsync(connection, ClassMappedNameCache.Get(), transaction); - var item4 = DataReader.ToEnumerable((DbDataReader)reader, dbFields, dbSetting)?.AsList(); + await reader.NextResultAsync(cancellationToken); + dbFields = await DbFieldCache.GetAsync(connection, ClassMappedNameCache.Get(), transaction, true, cancellationToken); + var item4 = await DataReader.ToEnumerableAsync(reader, dbFields, dbSetting, cancellationToken); // T5 - reader?.NextResult(); - dbFields = await DbFieldCache.GetAsync(connection, ClassMappedNameCache.Get(), transaction); - var item5 = DataReader.ToEnumerable((DbDataReader)reader, dbFields, dbSetting)?.AsList(); + await reader.NextResultAsync(cancellationToken); + dbFields = await DbFieldCache.GetAsync(connection, ClassMappedNameCache.Get(), transaction, true, cancellationToken); + var item5 = await DataReader.ToEnumerableAsync(reader, dbFields, dbSetting, cancellationToken); // T6 - reader?.NextResult(); - dbFields = await DbFieldCache.GetAsync(connection, ClassMappedNameCache.Get(), transaction); - var item6 = DataReader.ToEnumerable((DbDataReader)reader, dbFields, dbSetting)?.AsList(); + await reader.NextResultAsync(cancellationToken); + dbFields = await DbFieldCache.GetAsync(connection, ClassMappedNameCache.Get(), transaction, true, cancellationToken); + var item6 = await DataReader.ToEnumerableAsync(reader, dbFields, dbSetting, cancellationToken); // Result result = new Tuple, IEnumerable, IEnumerable, IEnumerable, IEnumerable, IEnumerable>( @@ -3261,6 +3292,7 @@ internal static async Task, IEnumerable, IEnumerableThe transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// A tuple of 7 enumerable target data entity types. public static Task, IEnumerable, IEnumerable, IEnumerable, IEnumerable, IEnumerable, IEnumerable>> QueryMultipleAsync(this IDbConnection connection, @@ -3295,7 +3327,8 @@ public static Task, IEnumerable, IEnumerable, IEnu int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where T1 : class where T2 : class where T3 : class @@ -3336,7 +3369,8 @@ public static Task, IEnumerable, IEnumerable, IEnu commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -3382,6 +3416,7 @@ public static Task, IEnumerable, IEnumerable, IEnu /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// A tuple of 7 enumerable target data entity types. internal static async Task, IEnumerable, IEnumerable, IEnumerable, IEnumerable, IEnumerable, IEnumerable>> QueryMultipleAsyncInternal(this IDbConnection connection, @@ -3416,7 +3451,8 @@ internal static async Task, IEnumerable, IEnumerable, IEnumerable, IEnumerable, IEnumerable, IEnumerable, IEnumerable, IEnumerable, IEnumerable, IEnumerable>)null; - using (var reader = await ExecuteReaderAsyncInternal(connection: connection, + using (var reader = (DbDataReader)await ExecuteReaderAsyncInternal(connection: connection, commandText: commandText, param: param, commandType: commandType, commandTimeout: commandTimeout, transaction: transaction, + cancellationToken: cancellationToken, entityType: null, dbFields: null, skipCommandArrayParametersCheck: true)) @@ -3574,38 +3611,38 @@ internal static async Task, IEnumerable, IEnumerable)null; // T1 - dbFields = await DbFieldCache.GetAsync(connection, ClassMappedNameCache.Get(), transaction); - var item1 = DataReader.ToEnumerable((DbDataReader)reader, dbFields, dbSetting)?.AsList(); + dbFields = await DbFieldCache.GetAsync(connection, ClassMappedNameCache.Get(), transaction, true, cancellationToken); + var item1 = await DataReader.ToEnumerableAsync(reader, dbFields, dbSetting, cancellationToken); // T2 - reader?.NextResult(); - dbFields = await DbFieldCache.GetAsync(connection, ClassMappedNameCache.Get(), transaction); - var item2 = DataReader.ToEnumerable((DbDataReader)reader, dbFields, dbSetting)?.AsList(); + await reader.NextResultAsync(cancellationToken); + dbFields = await DbFieldCache.GetAsync(connection, ClassMappedNameCache.Get(), transaction, true, cancellationToken); + var item2 = await DataReader.ToEnumerableAsync(reader, dbFields, dbSetting, cancellationToken); // T3 - reader?.NextResult(); - dbFields = await DbFieldCache.GetAsync(connection, ClassMappedNameCache.Get(), transaction); - var item3 = DataReader.ToEnumerable((DbDataReader)reader, dbFields, dbSetting)?.AsList(); + await reader.NextResultAsync(cancellationToken); + dbFields = await DbFieldCache.GetAsync(connection, ClassMappedNameCache.Get(), transaction, true, cancellationToken); + var item3 = await DataReader.ToEnumerableAsync(reader, dbFields, dbSetting, cancellationToken); // T4 - reader?.NextResult(); - dbFields = await DbFieldCache.GetAsync(connection, ClassMappedNameCache.Get(), transaction); - var item4 = DataReader.ToEnumerable((DbDataReader)reader, dbFields, dbSetting)?.AsList(); + await reader.NextResultAsync(cancellationToken); + dbFields = await DbFieldCache.GetAsync(connection, ClassMappedNameCache.Get(), transaction, true, cancellationToken); + var item4 = await DataReader.ToEnumerableAsync(reader, dbFields, dbSetting, cancellationToken); // T5 - reader?.NextResult(); - dbFields = await DbFieldCache.GetAsync(connection, ClassMappedNameCache.Get(), transaction); - var item5 = DataReader.ToEnumerable((DbDataReader)reader, dbFields, dbSetting)?.AsList(); + await reader.NextResultAsync(cancellationToken); + dbFields = await DbFieldCache.GetAsync(connection, ClassMappedNameCache.Get(), transaction, true, cancellationToken); + var item5 = await DataReader.ToEnumerableAsync(reader, dbFields, dbSetting, cancellationToken); // T6 - reader?.NextResult(); - dbFields = await DbFieldCache.GetAsync(connection, ClassMappedNameCache.Get(), transaction); - var item6 = DataReader.ToEnumerable((DbDataReader)reader, dbFields, dbSetting)?.AsList(); + await reader.NextResultAsync(cancellationToken); + dbFields = await DbFieldCache.GetAsync(connection, ClassMappedNameCache.Get(), transaction, true, cancellationToken); + var item6 = await DataReader.ToEnumerableAsync(reader, dbFields, dbSetting, cancellationToken); // T7 - reader?.NextResult(); - dbFields = await DbFieldCache.GetAsync(connection, ClassMappedNameCache.Get(), transaction); - var item7 = DataReader.ToEnumerable((DbDataReader)reader, dbFields, dbSetting)?.AsList(); + await reader.NextResultAsync(cancellationToken); + dbFields = await DbFieldCache.GetAsync(connection, ClassMappedNameCache.Get(), transaction, true, cancellationToken); + var item7 = await DataReader.ToEnumerableAsync(reader, dbFields, dbSetting, cancellationToken); // Result result = new Tuple, IEnumerable, IEnumerable, IEnumerable, IEnumerable, IEnumerable, IEnumerable>( diff --git a/RepoDb.Core/RepoDb/Operations/DbConnection/Sum.cs b/RepoDb.Core/RepoDb/Operations/DbConnection/Sum.cs index ceebc9a2e..1af8b51ff 100644 --- a/RepoDb.Core/RepoDb/Operations/DbConnection/Sum.cs +++ b/RepoDb.Core/RepoDb/Operations/DbConnection/Sum.cs @@ -7,6 +7,7 @@ using System.Data; using System.Linq; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -801,6 +802,7 @@ internal static TResult SumInternal(this IDbConnection connect /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public static Task SumAsync(this IDbConnection connection, Field field, @@ -809,7 +811,8 @@ public static Task SumAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return SumAsyncInternal(connection: connection, @@ -819,7 +822,8 @@ public static Task SumAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -834,6 +838,7 @@ public static Task SumAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public static Task SumAsync(this IDbConnection connection, Field field, @@ -842,7 +847,8 @@ public static Task SumAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return SumAsyncInternal(connection: connection, @@ -852,7 +858,8 @@ public static Task SumAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -867,6 +874,7 @@ public static Task SumAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public static Task SumAsync(this IDbConnection connection, Field field, @@ -875,7 +883,8 @@ public static Task SumAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return SumAsyncInternal(connection: connection, @@ -885,7 +894,8 @@ public static Task SumAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -900,6 +910,7 @@ public static Task SumAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public static Task SumAsync(this IDbConnection connection, Field field, @@ -908,7 +919,8 @@ public static Task SumAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return SumAsyncInternal(connection: connection, @@ -918,7 +930,8 @@ public static Task SumAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -933,6 +946,7 @@ public static Task SumAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public static Task SumAsync(this IDbConnection connection, Field field, @@ -941,7 +955,8 @@ public static Task SumAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return SumAsyncInternal(connection: connection, @@ -951,7 +966,8 @@ public static Task SumAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -966,6 +982,7 @@ public static Task SumAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public static Task SumAsync(this IDbConnection connection, Expression> field, @@ -974,7 +991,8 @@ public static Task SumAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return SumAsyncInternal(connection: connection, @@ -984,7 +1002,8 @@ public static Task SumAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -999,6 +1018,7 @@ public static Task SumAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public static Task SumAsync(this IDbConnection connection, Expression> field, @@ -1007,7 +1027,8 @@ public static Task SumAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return SumAsyncInternal(connection: connection, @@ -1017,7 +1038,8 @@ public static Task SumAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1032,6 +1054,7 @@ public static Task SumAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public static Task SumAsync(this IDbConnection connection, Expression> field, @@ -1040,7 +1063,8 @@ public static Task SumAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return SumAsyncInternal(connection: connection, @@ -1050,7 +1074,8 @@ public static Task SumAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1065,6 +1090,7 @@ public static Task SumAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public static Task SumAsync(this IDbConnection connection, Expression> field, @@ -1073,7 +1099,8 @@ public static Task SumAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return SumAsyncInternal(connection: connection, @@ -1083,7 +1110,8 @@ public static Task SumAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1098,6 +1126,7 @@ public static Task SumAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public static Task SumAsync(this IDbConnection connection, Expression> field, @@ -1106,7 +1135,8 @@ public static Task SumAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return SumAsyncInternal(connection: connection, @@ -1116,7 +1146,8 @@ public static Task SumAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1131,6 +1162,7 @@ public static Task SumAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. internal static Task SumAsyncInternal(this IDbConnection connection, Field field, @@ -1139,7 +1171,8 @@ internal static Task SumAsyncInternal(this IDbConnection connec string hints = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { // Variables @@ -1164,7 +1197,8 @@ internal static Task SumAsyncInternal(this IDbConnection connec param: param, commandTimeout: commandTimeout, transaction: transaction, - trace: trace); + trace: trace, + cancellationToken: cancellationToken); } /// @@ -1180,6 +1214,7 @@ internal static Task SumAsyncInternal(this IDbConnection connec /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public static Task SumAsync(this IDbConnection connection, Field field, @@ -1188,7 +1223,8 @@ public static Task SumAsync(this IDbConnection connec int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return SumAsyncInternal(connection: connection, @@ -1198,7 +1234,8 @@ public static Task SumAsync(this IDbConnection connec commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1214,6 +1251,7 @@ public static Task SumAsync(this IDbConnection connec /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public static Task SumAsync(this IDbConnection connection, Field field, @@ -1222,7 +1260,8 @@ public static Task SumAsync(this IDbConnection connec int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return SumAsyncInternal(connection: connection, @@ -1232,7 +1271,8 @@ public static Task SumAsync(this IDbConnection connec commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1248,6 +1288,7 @@ public static Task SumAsync(this IDbConnection connec /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public static Task SumAsync(this IDbConnection connection, Field field, @@ -1256,7 +1297,8 @@ public static Task SumAsync(this IDbConnection connec int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return SumAsyncInternal(connection: connection, @@ -1266,7 +1308,8 @@ public static Task SumAsync(this IDbConnection connec commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1282,6 +1325,7 @@ public static Task SumAsync(this IDbConnection connec /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public static Task SumAsync(this IDbConnection connection, Field field, @@ -1290,7 +1334,8 @@ public static Task SumAsync(this IDbConnection connec int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return SumAsyncInternal(connection: connection, @@ -1300,7 +1345,8 @@ public static Task SumAsync(this IDbConnection connec commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1316,6 +1362,7 @@ public static Task SumAsync(this IDbConnection connec /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public static Task SumAsync(this IDbConnection connection, Field field, @@ -1324,7 +1371,8 @@ public static Task SumAsync(this IDbConnection connec int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return SumAsyncInternal(connection: connection, @@ -1334,7 +1382,8 @@ public static Task SumAsync(this IDbConnection connec commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1350,6 +1399,7 @@ public static Task SumAsync(this IDbConnection connec /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public static Task SumAsync(this IDbConnection connection, Expression> field, @@ -1358,7 +1408,8 @@ public static Task SumAsync(this IDbConnection connec int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return SumAsyncInternal(connection: connection, @@ -1368,7 +1419,8 @@ public static Task SumAsync(this IDbConnection connec commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1384,6 +1436,7 @@ public static Task SumAsync(this IDbConnection connec /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public static Task SumAsync(this IDbConnection connection, Expression> field, @@ -1392,7 +1445,8 @@ public static Task SumAsync(this IDbConnection connec int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return SumAsyncInternal(connection: connection, @@ -1402,7 +1456,8 @@ public static Task SumAsync(this IDbConnection connec commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1418,6 +1473,7 @@ public static Task SumAsync(this IDbConnection connec /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public static Task SumAsync(this IDbConnection connection, Expression> field, @@ -1426,7 +1482,8 @@ public static Task SumAsync(this IDbConnection connec int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return SumAsyncInternal(connection: connection, @@ -1436,7 +1493,8 @@ public static Task SumAsync(this IDbConnection connec commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1452,6 +1510,7 @@ public static Task SumAsync(this IDbConnection connec /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public static Task SumAsync(this IDbConnection connection, Expression> field, @@ -1460,7 +1519,8 @@ public static Task SumAsync(this IDbConnection connec int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return SumAsyncInternal(connection: connection, @@ -1470,7 +1530,8 @@ public static Task SumAsync(this IDbConnection connec commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1486,6 +1547,7 @@ public static Task SumAsync(this IDbConnection connec /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public static Task SumAsync(this IDbConnection connection, Expression> field, @@ -1494,7 +1556,8 @@ public static Task SumAsync(this IDbConnection connec int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return SumAsyncInternal(connection: connection, @@ -1504,7 +1567,8 @@ public static Task SumAsync(this IDbConnection connec commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1520,6 +1584,7 @@ public static Task SumAsync(this IDbConnection connec /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. internal static Task SumAsyncInternal(this IDbConnection connection, Field field, @@ -1528,7 +1593,8 @@ internal static Task SumAsyncInternal(this IDbConnect string hints = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { // Variables @@ -1553,7 +1619,8 @@ internal static Task SumAsyncInternal(this IDbConnect param: param, commandTimeout: commandTimeout, transaction: transaction, - trace: trace); + trace: trace, + cancellationToken: cancellationToken); } #endregion @@ -1949,6 +2016,7 @@ internal static TResult SumInternal(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public static Task SumAsync(this IDbConnection connection, string tableName, @@ -1958,7 +2026,8 @@ public static Task SumAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return SumAsyncInternal(connection: connection, tableName: tableName, @@ -1968,7 +2037,8 @@ public static Task SumAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1983,6 +2053,7 @@ public static Task SumAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public static Task SumAsync(this IDbConnection connection, string tableName, @@ -1992,7 +2063,8 @@ public static Task SumAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return SumAsyncInternal(connection: connection, tableName: tableName, @@ -2002,7 +2074,8 @@ public static Task SumAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -2017,6 +2090,7 @@ public static Task SumAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public static Task SumAsync(this IDbConnection connection, string tableName, @@ -2026,7 +2100,8 @@ public static Task SumAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return SumAsyncInternal(connection: connection, tableName: tableName, @@ -2036,7 +2111,8 @@ public static Task SumAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -2051,6 +2127,7 @@ public static Task SumAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public static Task SumAsync(this IDbConnection connection, string tableName, @@ -2060,7 +2137,8 @@ public static Task SumAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return SumAsyncInternal(connection: connection, tableName: tableName, @@ -2070,7 +2148,8 @@ public static Task SumAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -2085,6 +2164,7 @@ public static Task SumAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. internal static Task SumAsyncInternal(this IDbConnection connection, string tableName, @@ -2094,7 +2174,8 @@ internal static Task SumAsyncInternal(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { // Variables var request = new SumRequest(tableName, @@ -2118,7 +2199,8 @@ internal static Task SumAsyncInternal(this IDbConnection connection, param: param, commandTimeout: commandTimeout, transaction: transaction, - trace: trace); + trace: trace, + cancellationToken: cancellationToken); } /// @@ -2134,6 +2216,7 @@ internal static Task SumAsyncInternal(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public static Task SumAsync(this IDbConnection connection, string tableName, @@ -2143,7 +2226,8 @@ public static Task SumAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return SumAsyncInternal(connection: connection, tableName: tableName, @@ -2153,7 +2237,8 @@ public static Task SumAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -2169,6 +2254,7 @@ public static Task SumAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public static Task SumAsync(this IDbConnection connection, string tableName, @@ -2178,7 +2264,8 @@ public static Task SumAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return SumAsyncInternal(connection: connection, tableName: tableName, @@ -2188,7 +2275,8 @@ public static Task SumAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -2204,6 +2292,7 @@ public static Task SumAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public static Task SumAsync(this IDbConnection connection, string tableName, @@ -2213,7 +2302,8 @@ public static Task SumAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return SumAsyncInternal(connection: connection, tableName: tableName, @@ -2223,7 +2313,8 @@ public static Task SumAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -2239,6 +2330,7 @@ public static Task SumAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public static Task SumAsync(this IDbConnection connection, string tableName, @@ -2248,7 +2340,8 @@ public static Task SumAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return SumAsyncInternal(connection: connection, tableName: tableName, @@ -2258,7 +2351,8 @@ public static Task SumAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -2274,6 +2368,7 @@ public static Task SumAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. internal static Task SumAsyncInternal(this IDbConnection connection, string tableName, @@ -2283,7 +2378,8 @@ internal static Task SumAsyncInternal(this IDbConnection conne int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { // Variables var request = new SumRequest(tableName, @@ -2307,7 +2403,8 @@ internal static Task SumAsyncInternal(this IDbConnection conne param: param, commandTimeout: commandTimeout, transaction: transaction, - trace: trace); + trace: trace, + cancellationToken: cancellationToken); } #endregion @@ -2392,13 +2489,15 @@ internal static TResult SumInternalBase(this IDbConnection connection, /// The command timeout in seconds to be used. /// The transaction to be used. /// The trace object to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. internal static async Task SumAsyncInternalBase(this IDbConnection connection, SumRequest request, object param, int? commandTimeout = null, IDbTransaction transaction = null, - ITrace trace = null) + ITrace trace = null, + CancellationToken cancellationToken = default) { // Variables var commandType = CommandType.Text; @@ -2433,8 +2532,9 @@ internal static async Task SumAsyncInternalBase(this IDbConnec commandType: commandType, commandTimeout: commandTimeout, transaction: transaction, + cancellationToken: cancellationToken, entityType: request.Type, - dbFields: await DbFieldCache.GetAsync(connection, request.Name, transaction, true), + dbFields: await DbFieldCache.GetAsync(connection, request.Name, transaction, true, cancellationToken), skipCommandArrayParametersCheck: true); // After Execution diff --git a/RepoDb.Core/RepoDb/Operations/DbConnection/SumAll.cs b/RepoDb.Core/RepoDb/Operations/DbConnection/SumAll.cs index 0201d0af7..9f7d6c5c7 100644 --- a/RepoDb.Core/RepoDb/Operations/DbConnection/SumAll.cs +++ b/RepoDb.Core/RepoDb/Operations/DbConnection/SumAll.cs @@ -5,6 +5,7 @@ using System.Data; using System.Linq; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -193,6 +194,7 @@ internal static TResult SumAllInternal(this IDbConnection conn /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public static Task SumAllAsync(this IDbConnection connection, Field field, @@ -200,7 +202,8 @@ public static Task SumAllAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return SumAllAsyncInternal(connection: connection, @@ -209,7 +212,8 @@ public static Task SumAllAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -223,6 +227,7 @@ public static Task SumAllAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public static Task SumAllAsync(this IDbConnection connection, Expression> field, @@ -230,7 +235,8 @@ public static Task SumAllAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return SumAllAsyncInternal(connection: connection, @@ -239,7 +245,8 @@ public static Task SumAllAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -254,6 +261,7 @@ public static Task SumAllAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public static Task SumAllAsync(this IDbConnection connection, Field field, @@ -261,7 +269,8 @@ public static Task SumAllAsync(this IDbConnection con int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return SumAllAsyncInternal(connection: connection, @@ -270,7 +279,8 @@ public static Task SumAllAsync(this IDbConnection con commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -285,6 +295,7 @@ public static Task SumAllAsync(this IDbConnection con /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public static Task SumAllAsync(this IDbConnection connection, Expression> field, @@ -292,7 +303,8 @@ public static Task SumAllAsync(this IDbConnection con int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return SumAllAsyncInternal(connection: connection, @@ -301,7 +313,8 @@ public static Task SumAllAsync(this IDbConnection con commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -316,6 +329,7 @@ public static Task SumAllAsync(this IDbConnection con /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. internal static Task SumAllAsyncInternal(this IDbConnection connection, Field field, @@ -323,7 +337,8 @@ internal static Task SumAllAsyncInternal(this IDbConn int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { // Variables @@ -341,7 +356,8 @@ internal static Task SumAllAsyncInternal(this IDbConn param: param, commandTimeout: commandTimeout, transaction: transaction, - trace: trace); + trace: trace, + cancellationToken: cancellationToken); } #endregion @@ -465,6 +481,7 @@ internal static TResult SumAllInternal(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public static Task SumAllAsync(this IDbConnection connection, string tableName, @@ -473,7 +490,8 @@ public static Task SumAllAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return SumAllAsyncInternal(connection: connection, tableName: tableName, @@ -482,7 +500,8 @@ public static Task SumAllAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -497,6 +516,7 @@ public static Task SumAllAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public static Task SumAllAsync(this IDbConnection connection, string tableName, @@ -505,7 +525,8 @@ public static Task SumAllAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return SumAllAsyncInternal(connection: connection, tableName: tableName, @@ -514,7 +535,8 @@ public static Task SumAllAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -529,6 +551,7 @@ public static Task SumAllAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. internal static Task SumAllAsyncInternal(this IDbConnection connection, string tableName, @@ -537,7 +560,8 @@ internal static Task SumAllAsyncInternal(this IDbConnection co int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { // Variables var request = new SumAllRequest(tableName, @@ -553,7 +577,8 @@ internal static Task SumAllAsyncInternal(this IDbConnection co param: null, commandTimeout: commandTimeout, transaction: transaction, - trace: trace); + trace: trace, + cancellationToken: cancellationToken); } #endregion @@ -640,13 +665,15 @@ internal static TResult SumAllInternalBase(this IDbConnection connectio /// The command timeout in seconds to be used. /// The transaction to be used. /// The trace object to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. internal static async Task SumAllAsyncInternalBase(this IDbConnection connection, SumAllRequest request, object param, int? commandTimeout = null, IDbTransaction transaction = null, - ITrace trace = null) + ITrace trace = null, + CancellationToken cancellationToken = default) { // Variables var commandType = CommandType.Text; @@ -681,8 +708,9 @@ internal static async Task SumAllAsyncInternalBase(this IDbCon commandType: commandType, commandTimeout: commandTimeout, transaction: transaction, + cancellationToken: cancellationToken, entityType: request.Type, - dbFields: await DbFieldCache.GetAsync(connection, request.Name, transaction, true), + dbFields: await DbFieldCache.GetAsync(connection, request.Name, transaction, true, cancellationToken), skipCommandArrayParametersCheck: true); // After Execution diff --git a/RepoDb.Core/RepoDb/Operations/DbConnection/Truncate.cs b/RepoDb.Core/RepoDb/Operations/DbConnection/Truncate.cs index 790a0cddf..098f767d7 100644 --- a/RepoDb.Core/RepoDb/Operations/DbConnection/Truncate.cs +++ b/RepoDb.Core/RepoDb/Operations/DbConnection/Truncate.cs @@ -3,6 +3,7 @@ using RepoDb.Requests; using System; using System.Data; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -82,19 +83,22 @@ internal static int TruncateInternal(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected. public static Task TruncateAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return TruncateAsyncInternal(connection: connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -106,12 +110,14 @@ public static Task TruncateAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected. internal static Task TruncateAsyncInternal(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { // Variables @@ -125,7 +131,8 @@ internal static Task TruncateAsyncInternal(this IDbConnection conn request: request, commandTimeout: commandTimeout, transaction: transaction, - trace: trace); + trace: trace, + cancellationToken: cancellationToken); } #endregion @@ -201,20 +208,23 @@ internal static int TruncateInternal(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected. public static Task TruncateAsync(this IDbConnection connection, string tableName, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return TruncateAsyncInternal(connection: connection, tableName: tableName, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -226,13 +236,15 @@ public static Task TruncateAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected. internal static Task TruncateAsyncInternal(this IDbConnection connection, string tableName, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { // Variables var request = new TruncateRequest(tableName, @@ -245,7 +257,8 @@ internal static Task TruncateAsyncInternal(this IDbConnection connection, request: request, commandTimeout: commandTimeout, transaction: transaction, - trace: trace); + trace: trace, + cancellationToken: cancellationToken); } #endregion @@ -325,12 +338,14 @@ internal static int TruncateInternalBase(this IDbConnection connection, /// The command timeout in seconds to be used. /// The transaction to be used. /// The trace object to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected. internal static async Task TruncateAsyncInternalBase(this IDbConnection connection, TruncateRequest request, int? commandTimeout = null, IDbTransaction transaction = null, - ITrace trace = null) + ITrace trace = null, + CancellationToken cancellationToken = default) { // Variables var commandType = CommandType.Text; @@ -363,8 +378,9 @@ internal static async Task TruncateAsyncInternalBase(this IDbConnection con commandType: commandType, commandTimeout: commandTimeout, transaction: transaction, + cancellationToken: cancellationToken, entityType: request.Type, - dbFields: await DbFieldCache.GetAsync(connection, request.Name, transaction, true), + dbFields: await DbFieldCache.GetAsync(connection, request.Name, transaction, true, cancellationToken), skipCommandArrayParametersCheck: true); // After Execution diff --git a/RepoDb.Core/RepoDb/Operations/DbConnection/Update.cs b/RepoDb.Core/RepoDb/Operations/DbConnection/Update.cs index 810841b36..ad99f4769 100644 --- a/RepoDb.Core/RepoDb/Operations/DbConnection/Update.cs +++ b/RepoDb.Core/RepoDb/Operations/DbConnection/Update.cs @@ -8,6 +8,7 @@ using System.Data.Common; using System.Linq; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -608,6 +609,7 @@ internal static int UpdateInternal(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public static async Task UpdateAsync(this IDbConnection connection, string tableName, @@ -617,11 +619,12 @@ public static async Task UpdateAsync(this IDbConnection connection int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { var key = await GetAndGuardPrimaryKeyOrIdentityKeyAsync(connection, tableName, transaction, - entity?.GetType() ?? typeof(TEntity)); + entity?.GetType() ?? typeof(TEntity), cancellationToken); return await UpdateAsyncInternal(connection: connection, tableName: tableName, entity: entity, @@ -631,7 +634,8 @@ public static async Task UpdateAsync(this IDbConnection connection commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -649,6 +653,7 @@ public static async Task UpdateAsync(this IDbConnection connection /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public static async Task UpdateAsync(this IDbConnection connection, string tableName, @@ -659,19 +664,21 @@ public static async Task UpdateAsync(this IDbConnection con int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return await UpdateAsyncInternal(connection: connection, tableName: tableName, entity: entity, - where: await WhatToQueryGroupAsync(connection, tableName, what, transaction), + where: await WhatToQueryGroupAsync(connection, tableName, what, transaction, cancellationToken), fields: fields, hints: hints, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -688,6 +695,7 @@ public static async Task UpdateAsync(this IDbConnection con /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public static async Task UpdateAsync(this IDbConnection connection, string tableName, @@ -698,19 +706,21 @@ public static async Task UpdateAsync(this IDbConnection connection int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return await UpdateAsyncInternal(connection: connection, tableName: tableName, entity: entity, - where: await WhatToQueryGroupAsync(connection, tableName, what, transaction), + where: await WhatToQueryGroupAsync(connection, tableName, what, transaction, cancellationToken), fields: fields, hints: hints, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -727,6 +737,7 @@ public static async Task UpdateAsync(this IDbConnection connection /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public static Task UpdateAsync(this IDbConnection connection, string tableName, @@ -737,7 +748,8 @@ public static Task UpdateAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return UpdateAsyncInternal(connection: connection, @@ -749,7 +761,8 @@ public static Task UpdateAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -766,6 +779,7 @@ public static Task UpdateAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public static Task UpdateAsync(this IDbConnection connection, string tableName, @@ -776,7 +790,8 @@ public static Task UpdateAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return UpdateAsyncInternal(connection: connection, @@ -788,7 +803,8 @@ public static Task UpdateAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -805,6 +821,7 @@ public static Task UpdateAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public static Task UpdateAsync(this IDbConnection connection, string tableName, @@ -815,7 +832,8 @@ public static Task UpdateAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return UpdateAsyncInternal(connection: connection, @@ -827,7 +845,8 @@ public static Task UpdateAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -844,6 +863,7 @@ public static Task UpdateAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public static Task UpdateAsync(this IDbConnection connection, string tableName, @@ -854,7 +874,8 @@ public static Task UpdateAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return UpdateAsyncInternal(connection: connection, @@ -866,7 +887,8 @@ public static Task UpdateAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -881,6 +903,7 @@ public static Task UpdateAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public static async Task UpdateAsync(this IDbConnection connection, TEntity entity, @@ -889,10 +912,11 @@ public static async Task UpdateAsync(this IDbConnection connection int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { - var key = await GetAndGuardPrimaryKeyOrIdentityKeyAsync(connection, transaction); + var key = await GetAndGuardPrimaryKeyOrIdentityKeyAsync(connection, transaction, cancellationToken); return await UpdateAsyncInternal(connection: connection, tableName: ClassMappedNameCache.Get(), entity: entity, @@ -902,7 +926,8 @@ public static async Task UpdateAsync(this IDbConnection connection commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -919,6 +944,7 @@ public static async Task UpdateAsync(this IDbConnection connection /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public static async Task UpdateAsync(this IDbConnection connection, TEntity entity, @@ -928,19 +954,21 @@ public static async Task UpdateAsync(this IDbConnection con int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return await UpdateAsyncInternal(connection: connection, tableName: ClassMappedNameCache.Get(), entity: entity, - where: await WhatToQueryGroupAsync(connection, what, transaction), + where: await WhatToQueryGroupAsync(connection, what, transaction, cancellationToken), fields: fields, hints: hints, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -956,6 +984,7 @@ public static async Task UpdateAsync(this IDbConnection con /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public static async Task UpdateAsync(this IDbConnection connection, TEntity entity, @@ -965,19 +994,21 @@ public static async Task UpdateAsync(this IDbConnection connection int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return await UpdateAsyncInternal(connection: connection, tableName: ClassMappedNameCache.Get(), entity: entity, - where: await WhatToQueryGroupAsync(connection, what, transaction), + where: await WhatToQueryGroupAsync(connection, what, transaction, cancellationToken), fields: fields, hints: hints, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -993,6 +1024,7 @@ public static async Task UpdateAsync(this IDbConnection connection /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public static Task UpdateAsync(this IDbConnection connection, TEntity entity, @@ -1002,7 +1034,8 @@ public static Task UpdateAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return UpdateAsyncInternal(connection: connection, @@ -1014,7 +1047,8 @@ public static Task UpdateAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1030,6 +1064,7 @@ public static Task UpdateAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public static Task UpdateAsync(this IDbConnection connection, TEntity entity, @@ -1039,7 +1074,8 @@ public static Task UpdateAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return UpdateAsyncInternal(connection: connection, @@ -1051,7 +1087,8 @@ public static Task UpdateAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1067,6 +1104,7 @@ public static Task UpdateAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public static Task UpdateAsync(this IDbConnection connection, TEntity entity, @@ -1076,7 +1114,8 @@ public static Task UpdateAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return UpdateAsyncInternal(connection: connection, @@ -1088,7 +1127,8 @@ public static Task UpdateAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1104,6 +1144,7 @@ public static Task UpdateAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public static Task UpdateAsync(this IDbConnection connection, TEntity entity, @@ -1113,7 +1154,8 @@ public static Task UpdateAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return UpdateAsyncInternal(connection: connection, @@ -1125,7 +1167,8 @@ public static Task UpdateAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1142,6 +1185,7 @@ public static Task UpdateAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. internal static Task UpdateAsyncInternal(this IDbConnection connection, string tableName, @@ -1152,7 +1196,8 @@ internal static Task UpdateAsyncInternal(this IDbConnection connec int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return UpdateAsyncInternalBase(connection: connection, @@ -1164,7 +1209,8 @@ internal static Task UpdateAsyncInternal(this IDbConnection connec commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } #endregion @@ -1371,6 +1417,7 @@ public static int Update(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public static async Task UpdateAsync(this IDbConnection connection, string tableName, @@ -1380,9 +1427,11 @@ public static async Task UpdateAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { - var key = await GetAndGuardPrimaryKeyOrIdentityKeyAsync(connection, tableName, transaction, entity?.GetType()); + var key = await GetAndGuardPrimaryKeyOrIdentityKeyAsync(connection, tableName, transaction, + entity?.GetType(), cancellationToken); return await UpdateAsyncInternal(connection: connection, tableName: tableName, entity: entity, @@ -1390,9 +1439,10 @@ public static async Task UpdateAsync(this IDbConnection connection, fields: fields, hints: hints, commandTimeout: commandTimeout, + transaction: transaction, trace: trace, statementBuilder: statementBuilder, - transaction: transaction); + cancellationToken: cancellationToken); } /// @@ -1408,6 +1458,7 @@ public static async Task UpdateAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public static Task UpdateAsync(this IDbConnection connection, string tableName, @@ -1418,7 +1469,8 @@ public static Task UpdateAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return UpdateAsyncInternal(connection: connection, tableName: tableName, @@ -1427,9 +1479,10 @@ public static Task UpdateAsync(this IDbConnection connection, fields: fields, hints: hints, commandTimeout: commandTimeout, + transaction: transaction, trace: trace, statementBuilder: statementBuilder, - transaction: transaction); + cancellationToken: cancellationToken); } /// @@ -1445,6 +1498,7 @@ public static Task UpdateAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public static Task UpdateAsync(this IDbConnection connection, string tableName, @@ -1455,7 +1509,8 @@ public static Task UpdateAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return UpdateAsyncInternal(connection: connection, tableName: tableName, @@ -1466,7 +1521,8 @@ public static Task UpdateAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1482,6 +1538,7 @@ public static Task UpdateAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public static Task UpdateAsync(this IDbConnection connection, string tableName, @@ -1492,7 +1549,8 @@ public static Task UpdateAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return UpdateAsyncInternal(connection: connection, tableName: tableName, @@ -1503,7 +1561,8 @@ public static Task UpdateAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -1519,6 +1578,7 @@ public static Task UpdateAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public static Task UpdateAsync(this IDbConnection connection, string tableName, @@ -1529,7 +1589,8 @@ public static Task UpdateAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return UpdateAsyncInternal(connection: connection, tableName: tableName, @@ -1540,7 +1601,8 @@ public static Task UpdateAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } #endregion @@ -1655,6 +1717,7 @@ internal static int UpdateInternalBase(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. internal static async Task UpdateAsyncInternalBase(this IDbConnection connection, string tableName, @@ -1665,7 +1728,8 @@ internal static async Task UpdateAsyncInternalBase(this IDbConnect int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { // Set the flags @@ -1678,7 +1742,8 @@ internal static async Task UpdateAsyncInternalBase(this IDbConnect fields, hints, transaction, - statementBuilder); + statementBuilder, + cancellationToken); var sessionId = Guid.Empty; // Before Execution @@ -1706,7 +1771,7 @@ internal static async Task UpdateAsyncInternalBase(this IDbConnect var result = 0; // Create the command - using (var command = (DbCommand)(await connection.EnsureOpenAsync()).CreateCommand(context.CommandText, + using (var command = (DbCommand)(await connection.EnsureOpenAsync(cancellationToken)).CreateCommand(context.CommandText, CommandType.Text, commandTimeout, transaction)) { // Set the values @@ -1714,10 +1779,10 @@ internal static async Task UpdateAsyncInternalBase(this IDbConnect // Add the fields from the query group WhereToCommandParameters(command, where, entity?.GetType(), - await DbFieldCache.GetAsync(connection, tableName, transaction)); + await DbFieldCache.GetAsync(connection, tableName, transaction, cancellationToken)); // Actual Execution - result = await command.ExecuteNonQueryAsync(); + result = await command.ExecuteNonQueryAsync(cancellationToken); } // After Execution diff --git a/RepoDb.Core/RepoDb/Operations/DbConnection/UpdateAll.cs b/RepoDb.Core/RepoDb/Operations/DbConnection/UpdateAll.cs index 3ed73a21c..fdafbf4f4 100644 --- a/RepoDb.Core/RepoDb/Operations/DbConnection/UpdateAll.cs +++ b/RepoDb.Core/RepoDb/Operations/DbConnection/UpdateAll.cs @@ -8,6 +8,7 @@ using System.Data.Common; using System.Linq; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; using System.Transactions; @@ -410,6 +411,7 @@ internal static int UpdateAllInternal(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public static Task UpdateAllAsync(this IDbConnection connection, string tableName, @@ -420,7 +422,8 @@ public static Task UpdateAllAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return UpdateAllAsyncInternal(connection: connection, @@ -433,7 +436,8 @@ public static Task UpdateAllAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -451,6 +455,7 @@ public static Task UpdateAllAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public static Task UpdateAllAsync(this IDbConnection connection, string tableName, @@ -462,7 +467,8 @@ public static Task UpdateAllAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return UpdateAllAsyncInternal(connection: connection, @@ -475,7 +481,8 @@ public static Task UpdateAllAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -493,6 +500,7 @@ public static Task UpdateAllAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public static Task UpdateAllAsync(this IDbConnection connection, string tableName, @@ -504,7 +512,8 @@ public static Task UpdateAllAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return UpdateAllAsyncInternal(connection: connection, @@ -517,7 +526,8 @@ public static Task UpdateAllAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -535,6 +545,7 @@ public static Task UpdateAllAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public static Task UpdateAllAsync(this IDbConnection connection, string tableName, @@ -546,7 +557,8 @@ public static Task UpdateAllAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return UpdateAllAsyncInternal(connection: connection, @@ -559,7 +571,8 @@ public static Task UpdateAllAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -575,6 +588,7 @@ public static Task UpdateAllAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public static Task UpdateAllAsync(this IDbConnection connection, IEnumerable entities, @@ -584,7 +598,8 @@ public static Task UpdateAllAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return UpdateAllAsyncInternal(connection: connection, @@ -597,7 +612,8 @@ public static Task UpdateAllAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -614,6 +630,7 @@ public static Task UpdateAllAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public static Task UpdateAllAsync(this IDbConnection connection, IEnumerable entities, @@ -624,7 +641,8 @@ public static Task UpdateAllAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return UpdateAllAsyncInternal(connection: connection, @@ -637,7 +655,8 @@ public static Task UpdateAllAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -654,6 +673,7 @@ public static Task UpdateAllAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public static Task UpdateAllAsync(this IDbConnection connection, IEnumerable entities, @@ -664,7 +684,8 @@ public static Task UpdateAllAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return UpdateAllAsyncInternal(connection: connection, @@ -677,7 +698,8 @@ public static Task UpdateAllAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -694,6 +716,7 @@ public static Task UpdateAllAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public static Task UpdateAllAsync(this IDbConnection connection, IEnumerable entities, @@ -704,7 +727,8 @@ public static Task UpdateAllAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { return UpdateAllAsyncInternal(connection: connection, @@ -717,7 +741,8 @@ public static Task UpdateAllAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -735,6 +760,7 @@ public static Task UpdateAllAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. internal static async Task UpdateAllAsyncInternal(this IDbConnection connection, string tableName, @@ -746,13 +772,14 @@ internal static async Task UpdateAllAsyncInternal(this IDbConnecti int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { if (qualifiers?.Any() != true) { var key = await GetAndGuardPrimaryKeyOrIdentityKeyAsync(connection, tableName, transaction, - entities?.FirstOrDefault()?.GetType() ?? typeof(TEntity)); + entities?.FirstOrDefault()?.GetType() ?? typeof(TEntity), cancellationToken); qualifiers = key.AsField().AsEnumerable(); } return await UpdateAllAsyncInternalBase(connection: connection, @@ -765,7 +792,8 @@ internal static async Task UpdateAllAsyncInternal(this IDbConnecti commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } #endregion @@ -907,6 +935,7 @@ public static int UpdateAll(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public static Task UpdateAllAsync(this IDbConnection connection, string tableName, @@ -917,7 +946,8 @@ public static Task UpdateAllAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return UpdateAllAsyncInternal(connection: connection, tableName: tableName, @@ -929,7 +959,8 @@ public static Task UpdateAllAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -946,6 +977,7 @@ public static Task UpdateAllAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public static Task UpdateAllAsync(this IDbConnection connection, string tableName, @@ -957,7 +989,8 @@ public static Task UpdateAllAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return UpdateAllAsyncInternal(connection: connection, tableName: tableName, @@ -969,7 +1002,8 @@ public static Task UpdateAllAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } /// @@ -986,6 +1020,7 @@ public static Task UpdateAllAsync(this IDbConnection connection, /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public static Task UpdateAllAsync(this IDbConnection connection, string tableName, @@ -997,7 +1032,8 @@ public static Task UpdateAllAsync(this IDbConnection connection, int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) { return UpdateAllAsyncInternal(connection: connection, tableName: tableName, @@ -1009,7 +1045,8 @@ public static Task UpdateAllAsync(this IDbConnection connection, commandTimeout: commandTimeout, transaction: transaction, trace: trace, - statementBuilder: statementBuilder); + statementBuilder: statementBuilder, + cancellationToken: cancellationToken); } #endregion @@ -1233,6 +1270,7 @@ internal static int UpdateAllInternalBase(this IDbConnection connection /// The transaction to be used. /// The trace object to be used. /// The statement builder object to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. internal static async Task UpdateAllAsyncInternalBase(this IDbConnection connection, string tableName, @@ -1244,7 +1282,8 @@ internal static async Task UpdateAllAsyncInternalBase(this IDbConn int? commandTimeout = null, IDbTransaction transaction = null, ITrace trace = null, - IStatementBuilder statementBuilder = null) + IStatementBuilder statementBuilder = null, + CancellationToken cancellationToken = default) where TEntity : class { // Variables needed @@ -1265,7 +1304,8 @@ internal static async Task UpdateAllAsyncInternalBase(this IDbConn fields, hints, transaction, - statementBuilder); + statementBuilder, + cancellationToken); var sessionId = Guid.Empty; // Before Execution @@ -1298,7 +1338,7 @@ internal static async Task UpdateAllAsyncInternalBase(this IDbConn try { // Ensure the connection is open - await connection.EnsureOpenAsync(); + await connection.EnsureOpenAsync(cancellationToken); if (hasTransaction == false) { @@ -1326,7 +1366,7 @@ internal static async Task UpdateAllAsyncInternalBase(this IDbConn } // Actual Execution - result += await command.ExecuteNonQueryAsync(); + result += await command.ExecuteNonQueryAsync(cancellationToken); } } else @@ -1353,7 +1393,8 @@ internal static async Task UpdateAllAsyncInternalBase(this IDbConn fields, hints, transaction, - statementBuilder); + statementBuilder, + cancellationToken); // Set the command properties command.CommandText = context.CommandText; @@ -1376,7 +1417,7 @@ internal static async Task UpdateAllAsyncInternalBase(this IDbConn } // Actual Execution - result += await command.ExecuteNonQueryAsync(); + result += await command.ExecuteNonQueryAsync(cancellationToken); } } } diff --git a/RepoDb.Core/RepoDb/Operations/DbRepository/Average.cs b/RepoDb.Core/RepoDb/Operations/DbRepository/Average.cs index dda366b82..c0e2cb328 100644 --- a/RepoDb.Core/RepoDb/Operations/DbRepository/Average.cs +++ b/RepoDb.Core/RepoDb/Operations/DbRepository/Average.cs @@ -3,6 +3,7 @@ using System.Data; using System.Data.Common; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -857,11 +858,13 @@ public TResult Average(Expression> fiel /// The dynamic expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public async Task AverageAsync(Field field, object where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -876,7 +879,8 @@ public async Task AverageAsync(Field field, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -898,11 +902,13 @@ public async Task AverageAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public async Task AverageAsync(Field field, Expression> where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -917,7 +923,8 @@ public async Task AverageAsync(Field field, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -939,11 +946,13 @@ public async Task AverageAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public async Task AverageAsync(Field field, QueryField where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -958,7 +967,8 @@ public async Task AverageAsync(Field field, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -980,11 +990,13 @@ public async Task AverageAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public async Task AverageAsync(Field field, IEnumerable where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -999,7 +1011,8 @@ public async Task AverageAsync(Field field, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1021,11 +1034,13 @@ public async Task AverageAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public async Task AverageAsync(Field field, QueryGroup where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1040,7 +1055,8 @@ public async Task AverageAsync(Field field, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1062,11 +1078,13 @@ public async Task AverageAsync(Field field, /// The dynamic expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public async Task AverageAsync(Expression> field, object where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1081,7 +1099,8 @@ public async Task AverageAsync(Expression commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1103,11 +1122,13 @@ public async Task AverageAsync(Expression /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public async Task AverageAsync(Expression> field, Expression> where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1122,7 +1143,8 @@ public async Task AverageAsync(Expression commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1144,11 +1166,13 @@ public async Task AverageAsync(Expression /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public async Task AverageAsync(Expression> field, QueryField where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1163,7 +1187,8 @@ public async Task AverageAsync(Expression commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1185,11 +1210,13 @@ public async Task AverageAsync(Expression /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public async Task AverageAsync(Expression> field, IEnumerable where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1204,7 +1231,8 @@ public async Task AverageAsync(Expression commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1226,11 +1254,13 @@ public async Task AverageAsync(Expression /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public async Task AverageAsync(Expression> field, QueryGroup where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1245,7 +1275,8 @@ public async Task AverageAsync(Expression commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1268,11 +1299,13 @@ public async Task AverageAsync(Expression /// The dynamic expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public async Task AverageAsync(Field field, object where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1287,7 +1320,8 @@ public async Task AverageAsync(Field field, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1310,11 +1344,13 @@ public async Task AverageAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public async Task AverageAsync(Field field, Expression> where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1329,7 +1365,8 @@ public async Task AverageAsync(Field field, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1352,11 +1389,13 @@ public async Task AverageAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public async Task AverageAsync(Field field, QueryField where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1371,7 +1410,8 @@ public async Task AverageAsync(Field field, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1394,11 +1434,13 @@ public async Task AverageAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public async Task AverageAsync(Field field, IEnumerable where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1413,7 +1455,8 @@ public async Task AverageAsync(Field field, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1436,11 +1479,13 @@ public async Task AverageAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public async Task AverageAsync(Field field, QueryGroup where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1455,7 +1500,8 @@ public async Task AverageAsync(Field field, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1478,11 +1524,13 @@ public async Task AverageAsync(Field field, /// The dynamic expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public async Task AverageAsync(Expression> field, object where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1497,7 +1545,8 @@ public async Task AverageAsync(Expression AverageAsync(ExpressionThe query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public async Task AverageAsync(Expression> field, Expression> where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1539,7 +1590,8 @@ public async Task AverageAsync(Expression AverageAsync(ExpressionThe query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public async Task AverageAsync(Expression> field, QueryField where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1581,7 +1635,8 @@ public async Task AverageAsync(Expression AverageAsync(ExpressionThe query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public async Task AverageAsync(Expression> field, IEnumerable where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1623,7 +1680,8 @@ public async Task AverageAsync(Expression AverageAsync(ExpressionThe query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public async Task AverageAsync(Expression> field, QueryGroup where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1665,7 +1725,8 @@ public async Task AverageAsync(Expression(string tableName, /// The dynamic expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public async Task AverageAsync(string tableName, Field field, object where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -2055,7 +2118,8 @@ public async Task AverageAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -2077,12 +2141,14 @@ public async Task AverageAsync(string tableName, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public async Task AverageAsync(string tableName, Field field, QueryField where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -2097,7 +2163,8 @@ public async Task AverageAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -2119,12 +2186,14 @@ public async Task AverageAsync(string tableName, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public async Task AverageAsync(string tableName, Field field, IEnumerable where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -2139,7 +2208,8 @@ public async Task AverageAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -2161,12 +2231,14 @@ public async Task AverageAsync(string tableName, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public async Task AverageAsync(string tableName, Field field, QueryGroup where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -2181,7 +2253,8 @@ public async Task AverageAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -2204,12 +2277,14 @@ public async Task AverageAsync(string tableName, /// The dynamic expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public async Task AverageAsync(string tableName, Field field, object where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -2224,7 +2299,8 @@ public async Task AverageAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -2247,12 +2323,14 @@ public async Task AverageAsync(string tableName, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public async Task AverageAsync(string tableName, Field field, QueryField where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -2267,7 +2345,8 @@ public async Task AverageAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -2290,12 +2369,14 @@ public async Task AverageAsync(string tableName, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public async Task AverageAsync(string tableName, Field field, IEnumerable where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -2310,7 +2391,8 @@ public async Task AverageAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -2333,12 +2415,14 @@ public async Task AverageAsync(string tableName, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public async Task AverageAsync(string tableName, Field field, QueryGroup where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -2353,7 +2437,8 @@ public async Task AverageAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { diff --git a/RepoDb.Core/RepoDb/Operations/DbRepository/AverageAll.cs b/RepoDb.Core/RepoDb/Operations/DbRepository/AverageAll.cs index ca9acfe2b..c846a8b53 100644 --- a/RepoDb.Core/RepoDb/Operations/DbRepository/AverageAll.cs +++ b/RepoDb.Core/RepoDb/Operations/DbRepository/AverageAll.cs @@ -2,6 +2,7 @@ using System.Data; using System.Data.Common; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -179,10 +180,12 @@ public TResult AverageAll(Expression> f /// The field to be averaged. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public async Task AverageAllAsync(Field field, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -196,7 +199,8 @@ public async Task AverageAllAsync(Field field, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -217,10 +221,12 @@ public async Task AverageAllAsync(Field field, /// The field to be averaged. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public async Task AverageAllAsync(Expression> field, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -234,7 +240,8 @@ public async Task AverageAllAsync(Expression AverageAllAsync(ExpressionThe field to be averaged. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public async Task AverageAllAsync(Field field, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -273,7 +282,8 @@ public async Task AverageAllAsync(Field field, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -295,10 +305,12 @@ public async Task AverageAllAsync(Field field, /// The field to be averaged. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public async Task AverageAllAsync(Expression> field, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -312,7 +324,8 @@ public async Task AverageAllAsync(Expression AverageAllAsync(Expression /// Computes the average value of the target field. /// - /// The transaction to be used. /// The name of the target table. /// The field to be averaged. /// The table hints to be used. + /// The transaction to be used. /// The average value of the target field. public object AverageAll(string tableName, Field field, @@ -373,10 +386,10 @@ public object AverageAll(string tableName, /// Computes the average value of the target field. /// /// The type of the result. - /// The transaction to be used. /// The name of the target table. /// The field to be averaged. /// The table hints to be used. + /// The transaction to be used. /// The average value of the target field. public TResult AverageAll(string tableName, Field field, @@ -416,15 +429,17 @@ public TResult AverageAll(string tableName, /// /// Computes the average value of the target field in an asynchronous way. /// - /// The transaction to be used. /// The name of the target table. /// The field to be averaged. /// The table hints to be used. + /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public async Task AverageAllAsync(string tableName, Field field, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -438,7 +453,8 @@ public async Task AverageAllAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -456,15 +472,17 @@ public async Task AverageAllAsync(string tableName, /// Computes the average value of the target field in an asynchronous way. /// /// The type of the result. - /// The transaction to be used. /// The name of the target table. /// The field to be averaged. /// The table hints to be used. + /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The average value of the target field. public async Task AverageAllAsync(string tableName, Field field, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -478,7 +496,8 @@ public async Task AverageAllAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { diff --git a/RepoDb.Core/RepoDb/Operations/DbRepository/BatchQuery.cs b/RepoDb.Core/RepoDb/Operations/DbRepository/BatchQuery.cs index 73d8ac750..e45012ff8 100644 --- a/RepoDb.Core/RepoDb/Operations/DbRepository/BatchQuery.cs +++ b/RepoDb.Core/RepoDb/Operations/DbRepository/BatchQuery.cs @@ -3,6 +3,7 @@ using System.Data; using System.Data.Common; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -642,6 +643,7 @@ public IEnumerable BatchQuery(int page, /// The list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public async Task> BatchQueryAsync(string tableName, int page, @@ -649,7 +651,8 @@ public async Task> BatchQueryAsync(string tableNam IEnumerable orderBy, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -667,7 +670,8 @@ public async Task> BatchQueryAsync(string tableNam commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -693,6 +697,7 @@ public async Task> BatchQueryAsync(string tableNam /// The list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public async Task> BatchQueryAsync(string tableName, int page, @@ -701,7 +706,8 @@ public async Task> BatchQueryAsync(string tableNam object where = null, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -720,7 +726,8 @@ public async Task> BatchQueryAsync(string tableNam commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -746,6 +753,7 @@ public async Task> BatchQueryAsync(string tableNam /// The list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public async Task> BatchQueryAsync(string tableName, int page, @@ -754,7 +762,8 @@ public async Task> BatchQueryAsync(string tableNam Expression> where = null, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { @@ -774,7 +783,8 @@ public async Task> BatchQueryAsync(string tableNam commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -800,6 +810,7 @@ public async Task> BatchQueryAsync(string tableNam /// The list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public async Task> BatchQueryAsync(string tableName, int page, @@ -808,7 +819,8 @@ public async Task> BatchQueryAsync(string tableNam QueryField where = null, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -827,7 +839,8 @@ public async Task> BatchQueryAsync(string tableNam commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -853,6 +866,7 @@ public async Task> BatchQueryAsync(string tableNam /// The list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public async Task> BatchQueryAsync(string tableName, int page, @@ -861,7 +875,8 @@ public async Task> BatchQueryAsync(string tableNam IEnumerable where = null, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -880,7 +895,8 @@ public async Task> BatchQueryAsync(string tableNam commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -904,13 +920,15 @@ public async Task> BatchQueryAsync(string tableNam /// The list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public async Task> BatchQueryAsync(int page, int rowsPerBatch, IEnumerable orderBy, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -927,7 +945,8 @@ public async Task> BatchQueryAsync(int page, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -952,6 +971,7 @@ public async Task> BatchQueryAsync(int page, /// The list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public async Task> BatchQueryAsync(int page, int rowsPerBatch, @@ -959,7 +979,8 @@ public async Task> BatchQueryAsync(int page, object where = null, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -978,7 +999,8 @@ public async Task> BatchQueryAsync(int page, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1003,6 +1025,7 @@ public async Task> BatchQueryAsync(int page, /// The list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public async Task> BatchQueryAsync(int page, int rowsPerBatch, @@ -1010,7 +1033,8 @@ public async Task> BatchQueryAsync(int page, Expression> where = null, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1029,7 +1053,8 @@ public async Task> BatchQueryAsync(int page, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1054,6 +1079,7 @@ public async Task> BatchQueryAsync(int page, /// The list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public async Task> BatchQueryAsync(int page, int rowsPerBatch, @@ -1061,7 +1087,8 @@ public async Task> BatchQueryAsync(int page, QueryField where = null, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1080,7 +1107,8 @@ public async Task> BatchQueryAsync(int page, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1105,6 +1133,7 @@ public async Task> BatchQueryAsync(int page, /// The list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public async Task> BatchQueryAsync(int page, int rowsPerBatch, @@ -1112,8 +1141,9 @@ public async Task> BatchQueryAsync(int page, IEnumerable where = null, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) - where TEntity : class + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) + where TEntity : class { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -1131,7 +1161,8 @@ public async Task> BatchQueryAsync(int page, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1156,6 +1187,7 @@ public async Task> BatchQueryAsync(int page, /// The list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public async Task> BatchQueryAsync(int page, int rowsPerBatch, @@ -1163,7 +1195,8 @@ public async Task> BatchQueryAsync(int page, QueryGroup where = null, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1182,7 +1215,8 @@ public async Task> BatchQueryAsync(int page, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1466,6 +1500,7 @@ public IEnumerable BatchQuery(string tableName, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of dynamic objects. public async Task> BatchQueryAsync(string tableName, int page, @@ -1473,7 +1508,8 @@ public async Task> BatchQueryAsync(string tableName, IEnumerable orderBy, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -1490,7 +1526,8 @@ public async Task> BatchQueryAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1515,6 +1552,7 @@ public async Task> BatchQueryAsync(string tableName, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of dynamic objects. public async Task> BatchQueryAsync(string tableName, int page, @@ -1523,7 +1561,8 @@ public async Task> BatchQueryAsync(string tableName, object where = null, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -1542,7 +1581,8 @@ public async Task> BatchQueryAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1567,6 +1607,7 @@ public async Task> BatchQueryAsync(string tableName, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of dynamic objects. public async Task> BatchQueryAsync(string tableName, int page, @@ -1575,7 +1616,8 @@ public async Task> BatchQueryAsync(string tableName, QueryField where = null, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -1594,7 +1636,8 @@ public async Task> BatchQueryAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1619,6 +1662,7 @@ public async Task> BatchQueryAsync(string tableName, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of dynamic objects. public async Task> BatchQueryAsync(string tableName, int page, @@ -1627,7 +1671,8 @@ public async Task> BatchQueryAsync(string tableName, IEnumerable where = null, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -1646,7 +1691,8 @@ public async Task> BatchQueryAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1671,6 +1717,7 @@ public async Task> BatchQueryAsync(string tableName, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of dynamic objects. public async Task> BatchQueryAsync(string tableName, int page, @@ -1679,7 +1726,8 @@ public async Task> BatchQueryAsync(string tableName, QueryGroup where = null, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -1698,7 +1746,8 @@ public async Task> BatchQueryAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { diff --git a/RepoDb.Core/RepoDb/Operations/DbRepository/Count.cs b/RepoDb.Core/RepoDb/Operations/DbRepository/Count.cs index fe69fbb8a..37fd73204 100644 --- a/RepoDb.Core/RepoDb/Operations/DbRepository/Count.cs +++ b/RepoDb.Core/RepoDb/Operations/DbRepository/Count.cs @@ -3,6 +3,7 @@ using System.Data; using System.Data.Common; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -216,10 +217,12 @@ public long Count(QueryGroup where = null, /// The dynamic expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An integer value that holds the number of rows from the table. public async Task CountAsync(object where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -233,7 +236,8 @@ public async Task CountAsync(object where = null, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -254,10 +258,12 @@ public async Task CountAsync(object where = null, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An integer value that holds the number of rows from the table. public async Task CountAsync(Expression> where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -271,7 +277,8 @@ public async Task CountAsync(Expression> wher commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -292,10 +299,12 @@ public async Task CountAsync(Expression> wher /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An integer value that holds the number of rows from the table. public async Task CountAsync(QueryField where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -309,7 +318,8 @@ public async Task CountAsync(QueryField where = null, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -330,10 +340,12 @@ public async Task CountAsync(QueryField where = null, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An integer value that holds the number of rows from the table. public async Task CountAsync(IEnumerable where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -347,7 +359,8 @@ public async Task CountAsync(IEnumerable where = null commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -368,10 +381,12 @@ public async Task CountAsync(IEnumerable where = null /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An integer value that holds the number of rows from the table. public async Task CountAsync(QueryGroup where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -385,7 +400,8 @@ public async Task CountAsync(QueryGroup where = null, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -570,11 +586,13 @@ public long Count(string tableName, /// The dynamic expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An integer value that holds the number of rows from the table. public async Task CountAsync(string tableName, object where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -588,7 +606,8 @@ public async Task CountAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -609,11 +628,13 @@ public async Task CountAsync(string tableName, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An integer value that holds the number of rows from the table. public async Task CountAsync(string tableName, QueryField where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -627,7 +648,8 @@ public async Task CountAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -648,11 +670,13 @@ public async Task CountAsync(string tableName, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An integer value that holds the number of rows from the table. public async Task CountAsync(string tableName, IEnumerable where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -666,7 +690,8 @@ public async Task CountAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -687,11 +712,13 @@ public async Task CountAsync(string tableName, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An integer value that holds the number of rows from the table. public async Task CountAsync(string tableName, QueryGroup where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -705,7 +732,8 @@ public async Task CountAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { diff --git a/RepoDb.Core/RepoDb/Operations/DbRepository/CountAll.cs b/RepoDb.Core/RepoDb/Operations/DbRepository/CountAll.cs index db1e4fe91..9af2855c6 100644 --- a/RepoDb.Core/RepoDb/Operations/DbRepository/CountAll.cs +++ b/RepoDb.Core/RepoDb/Operations/DbRepository/CountAll.cs @@ -1,6 +1,7 @@ using System; using System.Data; using System.Data.Common; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -58,9 +59,11 @@ public long CountAll(string hints = null, /// The type of the data entity. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An integer value that holds the number of rows from the table. public async Task CountAllAsync(string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -73,7 +76,8 @@ public async Task CountAllAsync(string hints = null, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -137,10 +141,12 @@ public long CountAll(string tableName, /// The transaction to be used. /// The name of the target table. /// The table hints to be used. + /// The object to be used during the asynchronous operation. /// An integer value that holds the number of rows from the table. public async Task CountAllAsync(string tableName, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -153,7 +159,8 @@ public async Task CountAllAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { diff --git a/RepoDb.Core/RepoDb/Operations/DbRepository/Delete.cs b/RepoDb.Core/RepoDb/Operations/DbRepository/Delete.cs index 506d89131..f1559f50d 100644 --- a/RepoDb.Core/RepoDb/Operations/DbRepository/Delete.cs +++ b/RepoDb.Core/RepoDb/Operations/DbRepository/Delete.cs @@ -3,6 +3,7 @@ using System.Data; using System.Data.Common; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -293,10 +294,12 @@ public int Delete(QueryGroup where, /// The data entity object to be deleted. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. public async Task DeleteAsync(TEntity entity, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -310,7 +313,8 @@ public async Task DeleteAsync(TEntity entity, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -332,10 +336,12 @@ public async Task DeleteAsync(TEntity entity, /// The dynamic expression or the key value to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. public async Task DeleteAsync(TWhat what, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -349,7 +355,8 @@ public async Task DeleteAsync(TWhat what, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -370,10 +377,12 @@ public async Task DeleteAsync(TWhat what, /// The dynamic expression or the key value to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. public async Task DeleteAsync(object what, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -387,7 +396,8 @@ public async Task DeleteAsync(object what, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -408,10 +418,12 @@ public async Task DeleteAsync(object what, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. public async Task DeleteAsync(Expression> where, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -425,7 +437,8 @@ public async Task DeleteAsync(Expression> wher commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -446,10 +459,12 @@ public async Task DeleteAsync(Expression> wher /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. public async Task DeleteAsync(QueryField where, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -463,7 +478,8 @@ public async Task DeleteAsync(QueryField where, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -484,10 +500,12 @@ public async Task DeleteAsync(QueryField where, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. public async Task DeleteAsync(IEnumerable where, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -501,7 +519,8 @@ public async Task DeleteAsync(IEnumerable where, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -522,10 +541,12 @@ public async Task DeleteAsync(IEnumerable where, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. public async Task DeleteAsync(QueryGroup where, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -539,7 +560,8 @@ public async Task DeleteAsync(QueryGroup where, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -765,11 +787,13 @@ public int Delete(string tableName, /// The data entity object, the dynamic expression or the key value to be deleted. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. public async Task DeleteAsync(string tableName, TWhat what, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -783,7 +807,8 @@ public async Task DeleteAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -804,11 +829,13 @@ public async Task DeleteAsync(string tableName, /// The data entity object, the dynamic expression or the key value to be deleted. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. public async Task DeleteAsync(string tableName, object what, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -822,7 +849,8 @@ public async Task DeleteAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -843,11 +871,13 @@ public async Task DeleteAsync(string tableName, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. public async Task DeleteAsync(string tableName, QueryField where, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -861,7 +891,8 @@ public async Task DeleteAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -882,11 +913,13 @@ public async Task DeleteAsync(string tableName, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. public async Task DeleteAsync(string tableName, IEnumerable where, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -900,7 +933,8 @@ public async Task DeleteAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -921,11 +955,13 @@ public async Task DeleteAsync(string tableName, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. public async Task DeleteAsync(string tableName, QueryGroup where, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -939,7 +975,8 @@ public async Task DeleteAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { diff --git a/RepoDb.Core/RepoDb/Operations/DbRepository/DeleteAll.cs b/RepoDb.Core/RepoDb/Operations/DbRepository/DeleteAll.cs index 184f065e1..e348da5ed 100644 --- a/RepoDb.Core/RepoDb/Operations/DbRepository/DeleteAll.cs +++ b/RepoDb.Core/RepoDb/Operations/DbRepository/DeleteAll.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Data; using System.Data.Common; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -300,11 +301,13 @@ public int DeleteAll(string hints = null, /// The list of data entity objects to be deleted. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. public async Task DeleteAllAsync(string tableName, IEnumerable entities, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -319,7 +322,8 @@ public async Task DeleteAllAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -342,11 +346,13 @@ public async Task DeleteAllAsync(string tableName, /// The list of the primary keys to be deleted. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. public async Task DeleteAllAsync(string tableName, IEnumerable keys, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -361,7 +367,8 @@ public async Task DeleteAllAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -383,11 +390,13 @@ public async Task DeleteAllAsync(string tableName, /// The list of the primary keys to be deleted. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. public async Task DeleteAllAsync(string tableName, IEnumerable keys, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -402,7 +411,8 @@ public async Task DeleteAllAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -423,10 +433,12 @@ public async Task DeleteAllAsync(string tableName, /// The list of data entity objects to be deleted. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. public async Task DeleteAllAsync(IEnumerable entities, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -440,7 +452,8 @@ public async Task DeleteAllAsync(IEnumerable entities, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -462,10 +475,12 @@ public async Task DeleteAllAsync(IEnumerable entities, /// The list of the primary keys to be deleted. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. public async Task DeleteAllAsync(IEnumerable keys, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -479,7 +494,8 @@ public async Task DeleteAllAsync(IEnumerable keys, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -500,10 +516,12 @@ public async Task DeleteAllAsync(IEnumerable keys, /// The list of the primary keys to be deleted. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. public async Task DeleteAllAsync(IEnumerable keys, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -517,7 +535,8 @@ public async Task DeleteAllAsync(IEnumerable keys, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -537,9 +556,11 @@ public async Task DeleteAllAsync(IEnumerable keys, /// The type of the data entity. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. public async Task DeleteAllAsync(string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -552,7 +573,8 @@ public async Task DeleteAllAsync(string hints = null, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -656,11 +678,13 @@ public int DeleteAll(string tableName, /// The list of the primary keys to be deleted. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. public async Task DeleteAllAsync(string tableName, IEnumerable keys, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -674,7 +698,8 @@ public async Task DeleteAllAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -694,10 +719,12 @@ public async Task DeleteAllAsync(string tableName, /// The table hints to be used. /// The transaction to be used. /// The name of the target table. + /// The object to be used during the asynchronous operation. /// The number of rows that has been deleted from the table. public async Task DeleteAllAsync(string tableName, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -710,7 +737,8 @@ public async Task DeleteAllAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { diff --git a/RepoDb.Core/RepoDb/Operations/DbRepository/Exists.cs b/RepoDb.Core/RepoDb/Operations/DbRepository/Exists.cs index c796d16ef..049a95f46 100644 --- a/RepoDb.Core/RepoDb/Operations/DbRepository/Exists.cs +++ b/RepoDb.Core/RepoDb/Operations/DbRepository/Exists.cs @@ -3,6 +3,7 @@ using System.Data; using System.Data.Common; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -255,10 +256,12 @@ public bool Exists(QueryGroup where, /// The dynamic expression or the key value to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// A boolean value that indicates whether the rows are existing in the table. public async Task ExistsAsync(object what, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -272,7 +275,8 @@ public async Task ExistsAsync(object what, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -294,10 +298,12 @@ public async Task ExistsAsync(object what, /// The dynamic expression or the key value to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// A boolean value that indicates whether the rows are existing in the table. public async Task ExistsAsync(TWhat what, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -311,7 +317,8 @@ public async Task ExistsAsync(TWhat what, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -332,10 +339,12 @@ public async Task ExistsAsync(TWhat what, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// A boolean value that indicates whether the rows are existing in the table. public async Task ExistsAsync(Expression> where, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -349,7 +358,8 @@ public async Task ExistsAsync(Expression> whe commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -370,10 +380,12 @@ public async Task ExistsAsync(Expression> whe /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// A boolean value that indicates whether the rows are existing in the table. public async Task ExistsAsync(QueryField where, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -387,7 +399,8 @@ public async Task ExistsAsync(QueryField where, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -408,10 +421,12 @@ public async Task ExistsAsync(QueryField where, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// A boolean value that indicates whether the rows are existing in the table. public async Task ExistsAsync(IEnumerable where, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -425,7 +440,8 @@ public async Task ExistsAsync(IEnumerable where, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -446,10 +462,12 @@ public async Task ExistsAsync(IEnumerable where, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// A boolean value that indicates whether the rows are existing in the table. public async Task ExistsAsync(QueryGroup where, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -463,7 +481,8 @@ public async Task ExistsAsync(QueryGroup where, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -689,11 +708,13 @@ public bool Exists(string tableName, /// The dynamic expression or the key value to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// A boolean value that indicates whether the rows are existing in the table. public async Task ExistsAsync(string tableName, TWhat what, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -707,7 +728,8 @@ public async Task ExistsAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -728,11 +750,13 @@ public async Task ExistsAsync(string tableName, /// The dynamic expression or the key value to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// A boolean value that indicates whether the rows are existing in the table. public async Task ExistsAsync(string tableName, object what, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -746,7 +770,8 @@ public async Task ExistsAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -767,11 +792,13 @@ public async Task ExistsAsync(string tableName, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// A boolean value that indicates whether the rows are existing in the table. public async Task ExistsAsync(string tableName, QueryField where, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -785,7 +812,8 @@ public async Task ExistsAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -806,11 +834,13 @@ public async Task ExistsAsync(string tableName, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// A boolean value that indicates whether the rows are existing in the table. public async Task ExistsAsync(string tableName, IEnumerable where, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -824,7 +854,8 @@ public async Task ExistsAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -845,11 +876,13 @@ public async Task ExistsAsync(string tableName, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// A boolean value that indicates whether the rows are existing in the table. public async Task ExistsAsync(string tableName, QueryGroup where, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -863,7 +896,8 @@ public async Task ExistsAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { diff --git a/RepoDb.Core/RepoDb/Operations/DbRepository/Insert.cs b/RepoDb.Core/RepoDb/Operations/DbRepository/Insert.cs index 9789ee011..ff38ec3ae 100644 --- a/RepoDb.Core/RepoDb/Operations/DbRepository/Insert.cs +++ b/RepoDb.Core/RepoDb/Operations/DbRepository/Insert.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Data; using System.Data.Common; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -199,12 +200,14 @@ public TResult Insert(TEntity entity, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public async Task InsertAsync(string tableName, TEntity entity, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -220,7 +223,8 @@ public async Task InsertAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -244,12 +248,14 @@ public async Task InsertAsync(string tableName, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public async Task InsertAsync(string tableName, TEntity entity, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -265,7 +271,8 @@ public async Task InsertAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -287,11 +294,13 @@ public async Task InsertAsync(string tableName, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public async Task InsertAsync(TEntity entity, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -306,7 +315,8 @@ public async Task InsertAsync(TEntity entity, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -329,11 +339,13 @@ public async Task InsertAsync(TEntity entity, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public async Task InsertAsync(TEntity entity, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -348,7 +360,8 @@ public async Task InsertAsync(TEntity entity, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -463,12 +476,14 @@ public TResult Insert(string tableName, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public async Task InsertAsync(string tableName, object entity, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -483,7 +498,8 @@ public async Task InsertAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -506,12 +522,14 @@ public async Task InsertAsync(string tableName, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The value of the primary key of the newly inserted data. public async Task InsertAsync(string tableName, object entity, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -526,7 +544,8 @@ public async Task InsertAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { diff --git a/RepoDb.Core/RepoDb/Operations/DbRepository/InsertAll.cs b/RepoDb.Core/RepoDb/Operations/DbRepository/InsertAll.cs index 3f783746f..eaf934ef3 100644 --- a/RepoDb.Core/RepoDb/Operations/DbRepository/InsertAll.cs +++ b/RepoDb.Core/RepoDb/Operations/DbRepository/InsertAll.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Data; using System.Data.Common; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -119,13 +120,15 @@ public int InsertAll(IEnumerable entities, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of inserted rows in the table. public async Task InsertAllAsync(string tableName, IEnumerable entities, int batchSize = Constant.DefaultBatchOperationSize, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -142,7 +145,8 @@ public async Task InsertAllAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -165,12 +169,14 @@ public async Task InsertAllAsync(string tableName, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of inserted rows in the table. public async Task InsertAllAsync(IEnumerable entities, int batchSize = Constant.DefaultBatchOperationSize, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -186,7 +192,8 @@ public async Task InsertAllAsync(IEnumerable entities, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -262,13 +269,15 @@ public int InsertAll(string tableName, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of inserted rows in the table. public async Task InsertAllAsync(string tableName, IEnumerable entities, int batchSize = Constant.DefaultBatchOperationSize, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -284,7 +293,8 @@ public async Task InsertAllAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { diff --git a/RepoDb.Core/RepoDb/Operations/DbRepository/Max.cs b/RepoDb.Core/RepoDb/Operations/DbRepository/Max.cs index fc892c70e..615349ab5 100644 --- a/RepoDb.Core/RepoDb/Operations/DbRepository/Max.cs +++ b/RepoDb.Core/RepoDb/Operations/DbRepository/Max.cs @@ -3,6 +3,7 @@ using System.Data; using System.Data.Common; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -857,11 +858,13 @@ public TResult Max(Expression> field, /// The dynamic expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public async Task MaxAsync(Field field, object where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -876,7 +879,8 @@ public async Task MaxAsync(Field field, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -898,11 +902,13 @@ public async Task MaxAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public async Task MaxAsync(Field field, Expression> where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -917,7 +923,8 @@ public async Task MaxAsync(Field field, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -939,11 +946,13 @@ public async Task MaxAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public async Task MaxAsync(Field field, QueryField where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -958,7 +967,8 @@ public async Task MaxAsync(Field field, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -980,11 +990,13 @@ public async Task MaxAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public async Task MaxAsync(Field field, IEnumerable where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -999,7 +1011,8 @@ public async Task MaxAsync(Field field, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1021,11 +1034,13 @@ public async Task MaxAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public async Task MaxAsync(Field field, QueryGroup where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1040,7 +1055,8 @@ public async Task MaxAsync(Field field, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1062,11 +1078,13 @@ public async Task MaxAsync(Field field, /// The dynamic expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public async Task MaxAsync(Expression> field, object where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1081,7 +1099,8 @@ public async Task MaxAsync(Expression> fi commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1103,11 +1122,13 @@ public async Task MaxAsync(Expression> fi /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public async Task MaxAsync(Expression> field, Expression> where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1122,7 +1143,8 @@ public async Task MaxAsync(Expression> fi commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1144,11 +1166,13 @@ public async Task MaxAsync(Expression> fi /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public async Task MaxAsync(Expression> field, QueryField where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1163,7 +1187,8 @@ public async Task MaxAsync(Expression> fi commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1185,11 +1210,13 @@ public async Task MaxAsync(Expression> fi /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public async Task MaxAsync(Expression> field, IEnumerable where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1204,7 +1231,8 @@ public async Task MaxAsync(Expression> fi commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1226,11 +1254,13 @@ public async Task MaxAsync(Expression> fi /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public async Task MaxAsync(Expression> field, QueryGroup where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1245,7 +1275,8 @@ public async Task MaxAsync(Expression> fi commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1268,11 +1299,13 @@ public async Task MaxAsync(Expression> fi /// The dynamic expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public async Task MaxAsync(Field field, object where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1287,7 +1320,8 @@ public async Task MaxAsync(Field field, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1310,11 +1344,13 @@ public async Task MaxAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public async Task MaxAsync(Field field, Expression> where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1329,7 +1365,8 @@ public async Task MaxAsync(Field field, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1352,11 +1389,13 @@ public async Task MaxAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public async Task MaxAsync(Field field, QueryField where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1371,7 +1410,8 @@ public async Task MaxAsync(Field field, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1394,11 +1434,13 @@ public async Task MaxAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public async Task MaxAsync(Field field, IEnumerable where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1413,7 +1455,8 @@ public async Task MaxAsync(Field field, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1436,11 +1479,13 @@ public async Task MaxAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public async Task MaxAsync(Field field, QueryGroup where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1455,7 +1500,8 @@ public async Task MaxAsync(Field field, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1478,11 +1524,13 @@ public async Task MaxAsync(Field field, /// The dynamic expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public async Task MaxAsync(Expression> field, object where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1497,7 +1545,8 @@ public async Task MaxAsync(Expression MaxAsync(ExpressionThe query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public async Task MaxAsync(Expression> field, Expression> where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1539,7 +1590,8 @@ public async Task MaxAsync(Expression MaxAsync(ExpressionThe query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public async Task MaxAsync(Expression> field, QueryField where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1581,7 +1635,8 @@ public async Task MaxAsync(Expression MaxAsync(ExpressionThe query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public async Task MaxAsync(Expression> field, IEnumerable where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1623,7 +1680,8 @@ public async Task MaxAsync(Expression MaxAsync(ExpressionThe query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public async Task MaxAsync(Expression> field, QueryGroup where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1665,7 +1725,8 @@ public async Task MaxAsync(Expression(string tableName, /// The dynamic expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public async Task MaxAsync(string tableName, Field field, object where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -2055,7 +2118,8 @@ public async Task MaxAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -2077,12 +2141,14 @@ public async Task MaxAsync(string tableName, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public async Task MaxAsync(string tableName, Field field, QueryField where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -2097,7 +2163,8 @@ public async Task MaxAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -2119,12 +2186,14 @@ public async Task MaxAsync(string tableName, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public async Task MaxAsync(string tableName, Field field, IEnumerable where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -2139,7 +2208,8 @@ public async Task MaxAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -2161,12 +2231,14 @@ public async Task MaxAsync(string tableName, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public async Task MaxAsync(string tableName, Field field, QueryGroup where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -2181,7 +2253,8 @@ public async Task MaxAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -2204,12 +2277,14 @@ public async Task MaxAsync(string tableName, /// The dynamic expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public async Task MaxAsync(string tableName, Field field, object where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -2224,7 +2299,8 @@ public async Task MaxAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -2247,12 +2323,14 @@ public async Task MaxAsync(string tableName, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public async Task MaxAsync(string tableName, Field field, QueryField where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -2267,7 +2345,8 @@ public async Task MaxAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -2290,12 +2369,14 @@ public async Task MaxAsync(string tableName, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public async Task MaxAsync(string tableName, Field field, IEnumerable where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -2310,7 +2391,8 @@ public async Task MaxAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -2333,12 +2415,14 @@ public async Task MaxAsync(string tableName, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public async Task MaxAsync(string tableName, Field field, QueryGroup where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -2353,7 +2437,8 @@ public async Task MaxAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { diff --git a/RepoDb.Core/RepoDb/Operations/DbRepository/MaxAll.cs b/RepoDb.Core/RepoDb/Operations/DbRepository/MaxAll.cs index 250f9cc34..c12c3c59f 100644 --- a/RepoDb.Core/RepoDb/Operations/DbRepository/MaxAll.cs +++ b/RepoDb.Core/RepoDb/Operations/DbRepository/MaxAll.cs @@ -2,6 +2,7 @@ using System.Data; using System.Data.Common; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -179,10 +180,12 @@ public TResult MaxAll(Expression> field /// The field to be maximized. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public async Task MaxAllAsync(Field field, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -196,7 +199,8 @@ public async Task MaxAllAsync(Field field, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -217,10 +221,12 @@ public async Task MaxAllAsync(Field field, /// The field to be maximized. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public async Task MaxAllAsync(Expression> field, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -234,7 +240,8 @@ public async Task MaxAllAsync(Expression> commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -256,10 +263,12 @@ public async Task MaxAllAsync(Expression> /// The field to be maximized. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public async Task MaxAllAsync(Field field, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -273,7 +282,8 @@ public async Task MaxAllAsync(Field field, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -295,10 +305,12 @@ public async Task MaxAllAsync(Field field, /// The field to be maximized. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public async Task MaxAllAsync(Expression> field, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -312,7 +324,8 @@ public async Task MaxAllAsync(Expression MaxAllAsync(Expression /// Computes the max value of the target field. /// - /// The transaction to be used. /// The name of the target table. /// The field to be maximized. /// The table hints to be used. + /// The transaction to be used. /// The max value of the target field. public object MaxAll(string tableName, Field field, @@ -373,10 +386,10 @@ public object MaxAll(string tableName, /// Computes the max value of the target field. /// /// The type of the result. - /// The transaction to be used. /// The name of the target table. /// The field to be maximized. /// The table hints to be used. + /// The transaction to be used. /// The max value of the target field. public TResult MaxAll(string tableName, Field field, @@ -416,15 +429,17 @@ public TResult MaxAll(string tableName, /// /// Computes the max value of the target field in an asynchronous way. /// - /// The transaction to be used. /// The name of the target table. /// The field to be maximized. /// The table hints to be used. + /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public async Task MaxAllAsync(string tableName, Field field, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -438,7 +453,8 @@ public async Task MaxAllAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -456,15 +472,17 @@ public async Task MaxAllAsync(string tableName, /// Computes the max value of the target field in an asynchronous way. /// /// The type of the result. - /// The transaction to be used. /// The name of the target table. /// The field to be maximized. /// The table hints to be used. + /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The max value of the target field. public async Task MaxAllAsync(string tableName, Field field, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -478,7 +496,8 @@ public async Task MaxAllAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { diff --git a/RepoDb.Core/RepoDb/Operations/DbRepository/Merge.cs b/RepoDb.Core/RepoDb/Operations/DbRepository/Merge.cs index 3ec3103f4..e953a11d4 100644 --- a/RepoDb.Core/RepoDb/Operations/DbRepository/Merge.cs +++ b/RepoDb.Core/RepoDb/Operations/DbRepository/Merge.cs @@ -3,6 +3,7 @@ using System.Data; using System.Data.Common; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -750,12 +751,14 @@ public TResult Merge(TEntity entity, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public async Task MergeAsync(string tableName, TEntity entity, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -771,7 +774,8 @@ public async Task MergeAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -795,13 +799,15 @@ public async Task MergeAsync(string tableName, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public async Task MergeAsync(string tableName, TEntity entity, Field qualifier, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -818,7 +824,8 @@ public async Task MergeAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -842,13 +849,15 @@ public async Task MergeAsync(string tableName, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public async Task MergeAsync(string tableName, TEntity entity, IEnumerable qualifiers, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -865,7 +874,8 @@ public async Task MergeAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -889,13 +899,15 @@ public async Task MergeAsync(string tableName, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public async Task MergeAsync(string tableName, TEntity entity, Expression> qualifiers, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -912,7 +924,8 @@ public async Task MergeAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -936,12 +949,14 @@ public async Task MergeAsync(string tableName, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public async Task MergeAsync(string tableName, TEntity entity, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -957,7 +972,8 @@ public async Task MergeAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -982,13 +998,15 @@ public async Task MergeAsync(string tableName, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public async Task MergeAsync(string tableName, TEntity entity, Field qualifier, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1005,7 +1023,8 @@ public async Task MergeAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1030,13 +1049,15 @@ public async Task MergeAsync(string tableName, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public async Task MergeAsync(string tableName, TEntity entity, IEnumerable qualifiers, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1053,7 +1074,8 @@ public async Task MergeAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1078,13 +1100,15 @@ public async Task MergeAsync(string tableName, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public async Task MergeAsync(string tableName, TEntity entity, Expression> qualifiers, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1101,7 +1125,8 @@ public async Task MergeAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1123,11 +1148,13 @@ public async Task MergeAsync(string tableName, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public async Task MergeAsync(TEntity entity, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1142,7 +1169,8 @@ public async Task MergeAsync(TEntity entity, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1165,12 +1193,14 @@ public async Task MergeAsync(TEntity entity, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public async Task MergeAsync(TEntity entity, Field qualifier, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1186,7 +1216,8 @@ public async Task MergeAsync(TEntity entity, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1209,12 +1240,14 @@ public async Task MergeAsync(TEntity entity, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public async Task MergeAsync(TEntity entity, IEnumerable qualifiers, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1230,7 +1263,8 @@ public async Task MergeAsync(TEntity entity, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1253,12 +1287,14 @@ public async Task MergeAsync(TEntity entity, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public async Task MergeAsync(TEntity entity, Expression> qualifiers, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1274,7 +1310,8 @@ public async Task MergeAsync(TEntity entity, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1297,11 +1334,13 @@ public async Task MergeAsync(TEntity entity, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public async Task MergeAsync(TEntity entity, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1316,7 +1355,8 @@ public async Task MergeAsync(TEntity entity, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1340,12 +1380,14 @@ public async Task MergeAsync(TEntity entity, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public async Task MergeAsync(TEntity entity, Field qualifier, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1361,7 +1403,8 @@ public async Task MergeAsync(TEntity entity, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1385,12 +1428,14 @@ public async Task MergeAsync(TEntity entity, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public async Task MergeAsync(TEntity entity, IEnumerable qualifiers, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1406,7 +1451,8 @@ public async Task MergeAsync(TEntity entity, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1430,12 +1476,14 @@ public async Task MergeAsync(TEntity entity, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public async Task MergeAsync(TEntity entity, Expression> qualifiers, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1451,7 +1499,8 @@ public async Task MergeAsync(TEntity entity, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1748,12 +1797,14 @@ public TResult Merge(string tableName, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public async Task MergeAsync(string tableName, object entity, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -1768,7 +1819,8 @@ public async Task MergeAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1791,13 +1843,15 @@ public async Task MergeAsync(string tableName, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public async Task MergeAsync(string tableName, object entity, Field qualifier, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -1813,7 +1867,8 @@ public async Task MergeAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1836,13 +1891,15 @@ public async Task MergeAsync(string tableName, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public async Task MergeAsync(string tableName, object entity, IEnumerable qualifiers, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -1858,7 +1915,8 @@ public async Task MergeAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1881,12 +1939,14 @@ public async Task MergeAsync(string tableName, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public async Task MergeAsync(string tableName, object entity, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -1901,7 +1961,8 @@ public async Task MergeAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1925,13 +1986,15 @@ public async Task MergeAsync(string tableName, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public async Task MergeAsync(string tableName, object entity, Field qualifier, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -1947,7 +2010,8 @@ public async Task MergeAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1971,13 +2035,15 @@ public async Task MergeAsync(string tableName, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The value of the identity field if present, otherwise, the value of the primary field. public async Task MergeAsync(string tableName, object entity, IEnumerable qualifiers, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -1993,7 +2059,8 @@ public async Task MergeAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { diff --git a/RepoDb.Core/RepoDb/Operations/DbRepository/MergeAll.cs b/RepoDb.Core/RepoDb/Operations/DbRepository/MergeAll.cs index 69662f838..7bd1e487b 100644 --- a/RepoDb.Core/RepoDb/Operations/DbRepository/MergeAll.cs +++ b/RepoDb.Core/RepoDb/Operations/DbRepository/MergeAll.cs @@ -3,6 +3,7 @@ using System.Data; using System.Data.Common; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -314,13 +315,15 @@ public int MergeAll(IEnumerable entities, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the merge process. public async Task MergeAllAsync(string tableName, IEnumerable entities, int batchSize = Constant.DefaultBatchOperationSize, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -337,7 +340,8 @@ public async Task MergeAllAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -362,6 +366,7 @@ public async Task MergeAllAsync(string tableName, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the merge process. public async Task MergeAllAsync(string tableName, IEnumerable entities, @@ -369,7 +374,8 @@ public async Task MergeAllAsync(string tableName, int batchSize = Constant.DefaultBatchOperationSize, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -387,7 +393,8 @@ public async Task MergeAllAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -412,6 +419,7 @@ public async Task MergeAllAsync(string tableName, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the merge process. public async Task MergeAllAsync(string tableName, IEnumerable entities, @@ -419,7 +427,8 @@ public async Task MergeAllAsync(string tableName, int batchSize = Constant.DefaultBatchOperationSize, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -437,7 +446,8 @@ public async Task MergeAllAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -460,12 +470,14 @@ public async Task MergeAllAsync(string tableName, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the merge process. public async Task MergeAllAsync(IEnumerable entities, int batchSize = Constant.DefaultBatchOperationSize, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -481,7 +493,8 @@ public async Task MergeAllAsync(IEnumerable entities, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -505,13 +518,15 @@ public async Task MergeAllAsync(IEnumerable entities, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the merge process. public async Task MergeAllAsync(IEnumerable entities, IEnumerable qualifiers, int batchSize = Constant.DefaultBatchOperationSize, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -528,7 +543,8 @@ public async Task MergeAllAsync(IEnumerable entities, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -552,13 +568,15 @@ public async Task MergeAllAsync(IEnumerable entities, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the merge process. public async Task MergeAllAsync(IEnumerable entities, Expression> qualifiers, int batchSize = Constant.DefaultBatchOperationSize, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -575,7 +593,8 @@ public async Task MergeAllAsync(IEnumerable entities, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -699,13 +718,15 @@ public int MergeAll(string tableName, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the merge process. public async Task MergeAllAsync(string tableName, IEnumerable entities, int batchSize = Constant.DefaultBatchOperationSize, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -721,7 +742,8 @@ public async Task MergeAllAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -745,6 +767,7 @@ public async Task MergeAllAsync(string tableName, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the merge process. public async Task MergeAllAsync(string tableName, IEnumerable entities, @@ -752,7 +775,8 @@ public async Task MergeAllAsync(string tableName, int batchSize = Constant.DefaultBatchOperationSize, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -769,7 +793,8 @@ public async Task MergeAllAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { diff --git a/RepoDb.Core/RepoDb/Operations/DbRepository/Min.cs b/RepoDb.Core/RepoDb/Operations/DbRepository/Min.cs index 531a477cd..6f77fc773 100644 --- a/RepoDb.Core/RepoDb/Operations/DbRepository/Min.cs +++ b/RepoDb.Core/RepoDb/Operations/DbRepository/Min.cs @@ -3,6 +3,7 @@ using System.Data; using System.Data.Common; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -857,11 +858,13 @@ public TResult Min(Expression> field, /// The dynamic expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public async Task MinAsync(Field field, object where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -876,7 +879,8 @@ public async Task MinAsync(Field field, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -898,11 +902,13 @@ public async Task MinAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public async Task MinAsync(Field field, Expression> where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -917,7 +923,8 @@ public async Task MinAsync(Field field, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -939,11 +946,13 @@ public async Task MinAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public async Task MinAsync(Field field, QueryField where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -958,7 +967,8 @@ public async Task MinAsync(Field field, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -980,11 +990,13 @@ public async Task MinAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public async Task MinAsync(Field field, IEnumerable where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -999,7 +1011,8 @@ public async Task MinAsync(Field field, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1021,11 +1034,13 @@ public async Task MinAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public async Task MinAsync(Field field, QueryGroup where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1040,7 +1055,8 @@ public async Task MinAsync(Field field, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1062,11 +1078,13 @@ public async Task MinAsync(Field field, /// The dynamic expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public async Task MinAsync(Expression> field, object where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1081,7 +1099,8 @@ public async Task MinAsync(Expression> fi commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1103,11 +1122,13 @@ public async Task MinAsync(Expression> fi /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public async Task MinAsync(Expression> field, Expression> where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1122,7 +1143,8 @@ public async Task MinAsync(Expression> fi commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1144,11 +1166,13 @@ public async Task MinAsync(Expression> fi /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public async Task MinAsync(Expression> field, QueryField where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1163,7 +1187,8 @@ public async Task MinAsync(Expression> fi commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1185,11 +1210,13 @@ public async Task MinAsync(Expression> fi /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public async Task MinAsync(Expression> field, IEnumerable where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1204,7 +1231,8 @@ public async Task MinAsync(Expression> fi commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1226,11 +1254,13 @@ public async Task MinAsync(Expression> fi /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public async Task MinAsync(Expression> field, QueryGroup where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1245,7 +1275,8 @@ public async Task MinAsync(Expression> fi commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1268,11 +1299,13 @@ public async Task MinAsync(Expression> fi /// The dynamic expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public async Task MinAsync(Field field, object where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1287,7 +1320,8 @@ public async Task MinAsync(Field field, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1310,11 +1344,13 @@ public async Task MinAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public async Task MinAsync(Field field, Expression> where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1329,7 +1365,8 @@ public async Task MinAsync(Field field, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1352,11 +1389,13 @@ public async Task MinAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public async Task MinAsync(Field field, QueryField where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1371,7 +1410,8 @@ public async Task MinAsync(Field field, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1394,11 +1434,13 @@ public async Task MinAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public async Task MinAsync(Field field, IEnumerable where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1413,7 +1455,8 @@ public async Task MinAsync(Field field, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1436,11 +1479,13 @@ public async Task MinAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public async Task MinAsync(Field field, QueryGroup where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1455,7 +1500,8 @@ public async Task MinAsync(Field field, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1478,11 +1524,13 @@ public async Task MinAsync(Field field, /// The dynamic expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public async Task MinAsync(Expression> field, object where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1497,7 +1545,8 @@ public async Task MinAsync(Expression MinAsync(ExpressionThe query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public async Task MinAsync(Expression> field, Expression> where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1539,7 +1590,8 @@ public async Task MinAsync(Expression MinAsync(ExpressionThe query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public async Task MinAsync(Expression> field, QueryField where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1581,7 +1635,8 @@ public async Task MinAsync(Expression MinAsync(ExpressionThe query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public async Task MinAsync(Expression> field, IEnumerable where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1623,7 +1680,8 @@ public async Task MinAsync(Expression MinAsync(ExpressionThe query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public async Task MinAsync(Expression> field, QueryGroup where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1665,7 +1725,8 @@ public async Task MinAsync(Expression(string tableName, /// The dynamic expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public async Task MinAsync(string tableName, Field field, object where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -2055,7 +2118,8 @@ public async Task MinAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -2077,12 +2141,14 @@ public async Task MinAsync(string tableName, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public async Task MinAsync(string tableName, Field field, QueryField where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -2097,7 +2163,8 @@ public async Task MinAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -2119,12 +2186,14 @@ public async Task MinAsync(string tableName, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public async Task MinAsync(string tableName, Field field, IEnumerable where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -2139,7 +2208,8 @@ public async Task MinAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -2161,12 +2231,14 @@ public async Task MinAsync(string tableName, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public async Task MinAsync(string tableName, Field field, QueryGroup where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -2181,7 +2253,8 @@ public async Task MinAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -2204,12 +2277,14 @@ public async Task MinAsync(string tableName, /// The dynamic expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public async Task MinAsync(string tableName, Field field, object where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -2224,7 +2299,8 @@ public async Task MinAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -2247,12 +2323,14 @@ public async Task MinAsync(string tableName, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public async Task MinAsync(string tableName, Field field, QueryField where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -2267,7 +2345,8 @@ public async Task MinAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -2290,12 +2369,14 @@ public async Task MinAsync(string tableName, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public async Task MinAsync(string tableName, Field field, IEnumerable where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -2310,7 +2391,8 @@ public async Task MinAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -2333,12 +2415,14 @@ public async Task MinAsync(string tableName, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public async Task MinAsync(string tableName, Field field, QueryGroup where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -2353,7 +2437,8 @@ public async Task MinAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { diff --git a/RepoDb.Core/RepoDb/Operations/DbRepository/MinAll.cs b/RepoDb.Core/RepoDb/Operations/DbRepository/MinAll.cs index ebaf1dfb5..210918049 100644 --- a/RepoDb.Core/RepoDb/Operations/DbRepository/MinAll.cs +++ b/RepoDb.Core/RepoDb/Operations/DbRepository/MinAll.cs @@ -2,6 +2,7 @@ using System.Data; using System.Data.Common; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -179,10 +180,12 @@ public TResult MinAll(Expression> field /// The field to be minimized. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public async Task MinAllAsync(Field field, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -196,7 +199,8 @@ public async Task MinAllAsync(Field field, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -217,10 +221,12 @@ public async Task MinAllAsync(Field field, /// The field to be minimized. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public async Task MinAllAsync(Expression> field, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -234,7 +240,8 @@ public async Task MinAllAsync(Expression> commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -256,10 +263,12 @@ public async Task MinAllAsync(Expression> /// The field to be minimized. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public async Task MinAllAsync(Field field, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -273,7 +282,8 @@ public async Task MinAllAsync(Field field, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -295,10 +305,12 @@ public async Task MinAllAsync(Field field, /// The field to be minimized. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public async Task MinAllAsync(Expression> field, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -312,7 +324,8 @@ public async Task MinAllAsync(Expression MinAllAsync(Expression /// Computes the min value of the target field. /// - /// The transaction to be used. /// The name of the target table. /// The field to be minimized. /// The table hints to be used. + /// The transaction to be used. /// The min value of the target field. public object MinAll(string tableName, Field field, @@ -373,10 +386,10 @@ public object MinAll(string tableName, /// Computes the min value of the target field. /// /// The type of the result. - /// The transaction to be used. /// The name of the target table. /// The field to be minimized. /// The table hints to be used. + /// The transaction to be used. /// The min value of the target field. public TResult MinAll(string tableName, Field field, @@ -416,15 +429,17 @@ public TResult MinAll(string tableName, /// /// Computes the min value of the target field in an asynchronous way. /// - /// The transaction to be used. /// The name of the target table. /// The field to be minimized. /// The table hints to be used. + /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public async Task MinAllAsync(string tableName, Field field, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -438,7 +453,8 @@ public async Task MinAllAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -456,15 +472,17 @@ public async Task MinAllAsync(string tableName, /// Computes the min value of the target field in an asynchronous way. /// /// The type of the result. - /// The transaction to be used. /// The name of the target table. /// The field to be minimized. /// The table hints to be used. + /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The min value of the target field. public async Task MinAllAsync(string tableName, Field field, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -478,7 +496,8 @@ public async Task MinAllAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { diff --git a/RepoDb.Core/RepoDb/Operations/DbRepository/Query.cs b/RepoDb.Core/RepoDb/Operations/DbRepository/Query.cs index 136527984..8aec4a091 100644 --- a/RepoDb.Core/RepoDb/Operations/DbRepository/Query.cs +++ b/RepoDb.Core/RepoDb/Operations/DbRepository/Query.cs @@ -3,6 +3,7 @@ using System.Data; using System.Data.Common; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -700,6 +701,7 @@ public IEnumerable Query(QueryGroup where, /// The key to the cache item.By setting this argument, it will return the item from the cache if present, otherwise it will query the database. /// /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public async Task> QueryAsync(string tableName, object what, @@ -708,7 +710,8 @@ public async Task> QueryAsync(string tableName, int? top = 0, string hints = null, string cacheKey = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -729,7 +732,8 @@ public async Task> QueryAsync(string tableName, transaction: transaction, cache: Cache, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -758,6 +762,7 @@ public async Task> QueryAsync(string tableName, /// The key to the cache item.By setting this argument, it will return the item from the cache if present, otherwise it will query the database. /// /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public async Task> QueryAsync(string tableName, TWhat what, @@ -766,7 +771,8 @@ public async Task> QueryAsync(string tableN int? top = 0, string hints = null, string cacheKey = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -787,7 +793,8 @@ public async Task> QueryAsync(string tableN transaction: transaction, cache: Cache, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -815,6 +822,7 @@ public async Task> QueryAsync(string tableN /// The key to the cache item.By setting this argument, it will return the item from the cache if present, otherwise it will query the database. /// /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public async Task> QueryAsync(string tableName, Expression> where, @@ -823,7 +831,8 @@ public async Task> QueryAsync(string tableName, int? top = 0, string hints = null, string cacheKey = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -844,7 +853,8 @@ public async Task> QueryAsync(string tableName, transaction: transaction, cache: Cache, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -872,6 +882,7 @@ public async Task> QueryAsync(string tableName, /// The key to the cache item.By setting this argument, it will return the item from the cache if present, otherwise it will query the database. /// /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public async Task> QueryAsync(string tableName, QueryField where, @@ -880,7 +891,8 @@ public async Task> QueryAsync(string tableName, int? top = 0, string hints = null, string cacheKey = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -901,7 +913,8 @@ public async Task> QueryAsync(string tableName, transaction: transaction, cache: Cache, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -929,6 +942,7 @@ public async Task> QueryAsync(string tableName, /// The key to the cache item.By setting this argument, it will return the item from the cache if present, otherwise it will query the database. /// /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public async Task> QueryAsync(string tableName, IEnumerable where, @@ -937,7 +951,8 @@ public async Task> QueryAsync(string tableName, int? top = 0, string hints = null, string cacheKey = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -958,7 +973,8 @@ public async Task> QueryAsync(string tableName, transaction: transaction, cache: Cache, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -986,6 +1002,7 @@ public async Task> QueryAsync(string tableName, /// The key to the cache item.By setting this argument, it will return the item from the cache if present, otherwise it will query the database. /// /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public async Task> QueryAsync(string tableName, QueryGroup where, @@ -994,7 +1011,8 @@ public async Task> QueryAsync(string tableName, int? top = 0, string hints = null, string cacheKey = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1015,7 +1033,8 @@ public async Task> QueryAsync(string tableName, transaction: transaction, cache: Cache, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1042,6 +1061,7 @@ public async Task> QueryAsync(string tableName, /// The key to the cache item.By setting this argument, it will return the item from the cache if present, otherwise it will query the database. /// /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public async Task> QueryAsync(object what, IEnumerable fields = null, @@ -1049,7 +1069,8 @@ public async Task> QueryAsync(object what, int? top = 0, string hints = null, string cacheKey = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1069,7 +1090,8 @@ public async Task> QueryAsync(object what, transaction: transaction, cache: Cache, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1097,6 +1119,7 @@ public async Task> QueryAsync(object what, /// The key to the cache item.By setting this argument, it will return the item from the cache if present, otherwise it will query the database. /// /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public async Task> QueryAsync(TWhat what, IEnumerable fields = null, @@ -1104,7 +1127,8 @@ public async Task> QueryAsync(TWhat what, int? top = 0, string hints = null, string cacheKey = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1124,7 +1148,8 @@ public async Task> QueryAsync(TWhat what, transaction: transaction, cache: Cache, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1151,6 +1176,7 @@ public async Task> QueryAsync(TWhat what, /// The key to the cache item.By setting this argument, it will return the item from the cache if present, otherwise it will query the database. /// /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public async Task> QueryAsync(Expression> where, IEnumerable fields = null, @@ -1158,7 +1184,8 @@ public async Task> QueryAsync(Expression> QueryAsync(Expression> QueryAsync(Expression /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public async Task> QueryAsync(QueryField where, IEnumerable fields = null, @@ -1212,7 +1241,8 @@ public async Task> QueryAsync(QueryField where, int? top = 0, string hints = null, string cacheKey = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1232,7 +1262,8 @@ public async Task> QueryAsync(QueryField where, transaction: transaction, cache: Cache, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1259,6 +1290,7 @@ public async Task> QueryAsync(QueryField where, /// The key to the cache item.By setting this argument, it will return the item from the cache if present, otherwise it will query the database. /// /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public async Task> QueryAsync(IEnumerable where, IEnumerable fields = null, @@ -1266,7 +1298,8 @@ public async Task> QueryAsync(IEnumerable> QueryAsync(IEnumerable> QueryAsync(IEnumerable /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public async Task> QueryAsync(QueryGroup where, IEnumerable fields = null, @@ -1320,7 +1355,8 @@ public async Task> QueryAsync(QueryGroup where, int? top = 0, string hints = null, string cacheKey = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1340,7 +1376,8 @@ public async Task> QueryAsync(QueryGroup where, transaction: transaction, cache: Cache, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1651,6 +1688,7 @@ public IEnumerable Query(string tableName, /// The key to the cache item.By setting this argument, it will return the item from the cache if present, otherwise it will query the database. /// /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of dynamic objects. public async Task> QueryAsync(string tableName, TWhat what, @@ -1659,7 +1697,8 @@ public async Task> QueryAsync(string tableName, int? top = 0, string hints = null, string cacheKey = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -1679,7 +1718,8 @@ public async Task> QueryAsync(string tableName, transaction: transaction, cache: Cache, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1706,6 +1746,7 @@ public async Task> QueryAsync(string tableName, /// The key to the cache item.By setting this argument, it will return the item from the cache if present, otherwise it will query the database. /// /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of dynamic objects. public async Task> QueryAsync(string tableName, object what, @@ -1714,7 +1755,8 @@ public async Task> QueryAsync(string tableName, int? top = 0, string hints = null, string cacheKey = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -1734,7 +1776,8 @@ public async Task> QueryAsync(string tableName, transaction: transaction, cache: Cache, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1761,6 +1804,7 @@ public async Task> QueryAsync(string tableName, /// The key to the cache item.By setting this argument, it will return the item from the cache if present, otherwise it will query the database. /// /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of dynamic objects. public async Task> QueryAsync(string tableName, QueryField where, @@ -1769,7 +1813,8 @@ public async Task> QueryAsync(string tableName, int? top = 0, string hints = null, string cacheKey = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -1789,7 +1834,8 @@ public async Task> QueryAsync(string tableName, transaction: transaction, cache: Cache, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1816,6 +1862,7 @@ public async Task> QueryAsync(string tableName, /// The key to the cache item.By setting this argument, it will return the item from the cache if present, otherwise it will query the database. /// /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of dynamic objects. public async Task> QueryAsync(string tableName, IEnumerable where, @@ -1824,7 +1871,8 @@ public async Task> QueryAsync(string tableName, int? top = 0, string hints = null, string cacheKey = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -1844,7 +1892,8 @@ public async Task> QueryAsync(string tableName, transaction: transaction, cache: Cache, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1871,6 +1920,7 @@ public async Task> QueryAsync(string tableName, /// The key to the cache item.By setting this argument, it will return the item from the cache if present, otherwise it will query the database. /// /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of dynamic objects. public async Task> QueryAsync(string tableName, QueryGroup where, @@ -1879,7 +1929,8 @@ public async Task> QueryAsync(string tableName, int? top = 0, string hints = null, string cacheKey = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -1899,7 +1950,8 @@ public async Task> QueryAsync(string tableName, transaction: transaction, cache: Cache, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { diff --git a/RepoDb.Core/RepoDb/Operations/DbRepository/QueryAll.cs b/RepoDb.Core/RepoDb/Operations/DbRepository/QueryAll.cs index 4d304b74e..864962408 100644 --- a/RepoDb.Core/RepoDb/Operations/DbRepository/QueryAll.cs +++ b/RepoDb.Core/RepoDb/Operations/DbRepository/QueryAll.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Data; using System.Data.Common; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -77,7 +78,7 @@ public IEnumerable QueryAll(string tableName, /// /// The transaction to be used. /// An enumerable list of data entity objects. - public IEnumerable QueryAll(IEnumerable fields = null, + public IEnumerable QueryAll(IEnumerable fields = null, IEnumerable orderBy = null, string hints = null, string cacheKey = null, @@ -129,13 +130,15 @@ public IEnumerable QueryAll(IEnumerable fields = null, /// The key to the cache item.By setting this argument, it will return the item from the cache if present, otherwise it will query the database. /// /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public async Task> QueryAllAsync(string tableName, IEnumerable fields = null, IEnumerable orderBy = null, string hints = null, string cacheKey = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -154,7 +157,8 @@ public async Task> QueryAllAsync(string tableName, transaction: transaction, cache: Cache, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -179,12 +183,14 @@ public async Task> QueryAllAsync(string tableName, /// The key to the cache item.By setting this argument, it will return the item from the cache if present, otherwise it will query the database. /// /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public async Task> QueryAllAsync(IEnumerable fields = null, IEnumerable orderBy = null, string hints = null, string cacheKey = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -202,7 +208,8 @@ public async Task> QueryAllAsync(IEnumerable QueryAll(string tableName, /// The key to the cache item.By setting this argument, it will return the item from the cache if present, otherwise it will query the database. /// /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// An enumerable list of data entity objects. public async Task> QueryAllAsync(string tableName, IEnumerable fields = null, IEnumerable orderBy = null, string hints = null, string cacheKey = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -308,7 +317,8 @@ public async Task> QueryAllAsync(string tableName, transaction: transaction, cache: Cache, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { diff --git a/RepoDb.Core/RepoDb/Operations/DbRepository/QueryMultiple.cs b/RepoDb.Core/RepoDb/Operations/DbRepository/QueryMultiple.cs index 76951a8e4..f44b46cf5 100644 --- a/RepoDb.Core/RepoDb/Operations/DbRepository/QueryMultiple.cs +++ b/RepoDb.Core/RepoDb/Operations/DbRepository/QueryMultiple.cs @@ -3,6 +3,7 @@ using System.Data; using System.Data.Common; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -621,6 +622,7 @@ public Tuple, IEnumerable, IEnumerable, IEnumerable, /// The number of rows to be returned (at T2). /// The table hints to be used (at T2). /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// A tuple of 2 enumerable target data entity types. public async Task, IEnumerable>> QueryMultipleAsync(Expression> where1, Expression> where2, @@ -630,7 +632,8 @@ public async Task, IEnumerable>> QueryMultipleAsync orderBy2 = null, string hints2 = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where T1 : class where T2 : class { @@ -651,7 +654,8 @@ public async Task, IEnumerable>> QueryMultipleAsync, IEnumerable>> QueryMultipleAsyncThe number of rows to be returned (at T3). /// The table hints to be used (at T3). /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// A tuple of 3 enumerable target data entity types. public async Task, IEnumerable, IEnumerable>> QueryMultipleAsync(Expression> where1, Expression> where2, @@ -701,7 +706,8 @@ public async Task, IEnumerable, IEnumerable>> Quer IEnumerable orderBy3 = null, int? top3 = 0, string hints3 = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where T1 : class where T2 : class where T3 : class @@ -727,7 +733,8 @@ public async Task, IEnumerable, IEnumerable>> Quer commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -769,6 +776,7 @@ public async Task, IEnumerable, IEnumerable>> Quer /// The number of rows to be returned (at T4). /// The table hints to be used (at T4). /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// A tuple of 4 enumerable target data entity types. public async Task, IEnumerable, IEnumerable, IEnumerable>> QueryMultipleAsync(Expression> where1, @@ -787,7 +795,8 @@ public async Task, IEnumerable, IEnumerable, IEnum IEnumerable orderBy4 = null, int? top4 = 0, string hints4 = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where T1 : class where T2 : class where T3 : class @@ -818,7 +827,8 @@ public async Task, IEnumerable, IEnumerable, IEnum commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -865,6 +875,7 @@ public async Task, IEnumerable, IEnumerable, IEnum /// The number of rows to be returned (at T5). /// The table hints to be used (at T5). /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// A tuple of 5 enumerable target data entity types. public async Task, IEnumerable, IEnumerable, IEnumerable, IEnumerable>> QueryMultipleAsync(Expression> where1, @@ -887,7 +898,8 @@ public async Task, IEnumerable, IEnumerable, IEnum IEnumerable orderBy5 = null, int? top5 = 0, string hints5 = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where T1 : class where T2 : class where T3 : class @@ -923,7 +935,8 @@ public async Task, IEnumerable, IEnumerable, IEnum commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -975,6 +988,7 @@ public async Task, IEnumerable, IEnumerable, IEnum /// The number of rows to be returned (at T6). /// The table hints to be used (at T6). /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// A tuple of 6 enumerable target data entity types. public async Task, IEnumerable, IEnumerable, IEnumerable, IEnumerable, IEnumerable>> QueryMultipleAsync(Expression> where1, @@ -1001,7 +1015,8 @@ public async Task, IEnumerable, IEnumerable, IEnum IEnumerable orderBy6 = null, int? top6 = 0, string hints6 = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where T1 : class where T2 : class where T3 : class @@ -1042,7 +1057,8 @@ public async Task, IEnumerable, IEnumerable, IEnum commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1099,6 +1115,7 @@ public async Task, IEnumerable, IEnumerable, IEnum /// The number of rows to be returned (at T7). /// The table hints to be used (at T7). /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// A tuple of 7 enumerable target data entity types. public async Task, IEnumerable, IEnumerable, IEnumerable, IEnumerable, IEnumerable, IEnumerable>> QueryMultipleAsync(Expression> where1, @@ -1129,7 +1146,8 @@ public async Task, IEnumerable, IEnumerable, IEnum IEnumerable orderBy7 = null, int? top7 = 0, string hints7 = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where T1 : class where T2 : class where T3 : class @@ -1175,7 +1193,8 @@ public async Task, IEnumerable, IEnumerable, IEnum commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { diff --git a/RepoDb.Core/RepoDb/Operations/DbRepository/Sum.cs b/RepoDb.Core/RepoDb/Operations/DbRepository/Sum.cs index 3faa1eadf..d8eb5ba78 100644 --- a/RepoDb.Core/RepoDb/Operations/DbRepository/Sum.cs +++ b/RepoDb.Core/RepoDb/Operations/DbRepository/Sum.cs @@ -3,6 +3,7 @@ using System.Data; using System.Data.Common; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -857,11 +858,13 @@ public TResult Sum(Expression> field, /// The dynamic expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public async Task SumAsync(Field field, object where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -876,7 +879,8 @@ public async Task SumAsync(Field field, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -898,11 +902,13 @@ public async Task SumAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public async Task SumAsync(Field field, Expression> where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -917,7 +923,8 @@ public async Task SumAsync(Field field, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -939,11 +946,13 @@ public async Task SumAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public async Task SumAsync(Field field, QueryField where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -958,7 +967,8 @@ public async Task SumAsync(Field field, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -980,11 +990,13 @@ public async Task SumAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public async Task SumAsync(Field field, IEnumerable where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -999,7 +1011,8 @@ public async Task SumAsync(Field field, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1021,11 +1034,13 @@ public async Task SumAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public async Task SumAsync(Field field, QueryGroup where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1040,7 +1055,8 @@ public async Task SumAsync(Field field, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1062,11 +1078,13 @@ public async Task SumAsync(Field field, /// The dynamic expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public async Task SumAsync(Expression> field, object where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1081,7 +1099,8 @@ public async Task SumAsync(Expression> fi commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1103,11 +1122,13 @@ public async Task SumAsync(Expression> fi /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public async Task SumAsync(Expression> field, Expression> where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1122,7 +1143,8 @@ public async Task SumAsync(Expression> fi commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1144,11 +1166,13 @@ public async Task SumAsync(Expression> fi /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public async Task SumAsync(Expression> field, QueryField where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1163,7 +1187,8 @@ public async Task SumAsync(Expression> fi commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1185,11 +1210,13 @@ public async Task SumAsync(Expression> fi /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public async Task SumAsync(Expression> field, IEnumerable where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1204,7 +1231,8 @@ public async Task SumAsync(Expression> fi commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1226,11 +1254,13 @@ public async Task SumAsync(Expression> fi /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public async Task SumAsync(Expression> field, QueryGroup where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1245,7 +1275,8 @@ public async Task SumAsync(Expression> fi commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1268,11 +1299,13 @@ public async Task SumAsync(Expression> fi /// The dynamic expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public async Task SumAsync(Field field, object where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1287,7 +1320,8 @@ public async Task SumAsync(Field field, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1310,11 +1344,13 @@ public async Task SumAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public async Task SumAsync(Field field, Expression> where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1329,7 +1365,8 @@ public async Task SumAsync(Field field, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1352,11 +1389,13 @@ public async Task SumAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public async Task SumAsync(Field field, QueryField where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1371,7 +1410,8 @@ public async Task SumAsync(Field field, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1394,11 +1434,13 @@ public async Task SumAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public async Task SumAsync(Field field, IEnumerable where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1413,7 +1455,8 @@ public async Task SumAsync(Field field, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1436,11 +1479,13 @@ public async Task SumAsync(Field field, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public async Task SumAsync(Field field, QueryGroup where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1455,7 +1500,8 @@ public async Task SumAsync(Field field, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1478,11 +1524,13 @@ public async Task SumAsync(Field field, /// The dynamic expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public async Task SumAsync(Expression> field, object where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1497,7 +1545,8 @@ public async Task SumAsync(Expression SumAsync(ExpressionThe query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public async Task SumAsync(Expression> field, Expression> where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1539,7 +1590,8 @@ public async Task SumAsync(Expression SumAsync(ExpressionThe query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public async Task SumAsync(Expression> field, QueryField where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1581,7 +1635,8 @@ public async Task SumAsync(Expression SumAsync(ExpressionThe query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public async Task SumAsync(Expression> field, IEnumerable where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1623,7 +1680,8 @@ public async Task SumAsync(Expression SumAsync(ExpressionThe query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public async Task SumAsync(Expression> field, QueryGroup where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1665,7 +1725,8 @@ public async Task SumAsync(Expression(string tableName, /// The dynamic expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public async Task SumAsync(string tableName, Field field, object where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -2055,7 +2118,8 @@ public async Task SumAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -2077,12 +2141,14 @@ public async Task SumAsync(string tableName, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public async Task SumAsync(string tableName, Field field, QueryField where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -2097,7 +2163,8 @@ public async Task SumAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -2119,12 +2186,14 @@ public async Task SumAsync(string tableName, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public async Task SumAsync(string tableName, Field field, IEnumerable where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -2139,7 +2208,8 @@ public async Task SumAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -2161,12 +2231,14 @@ public async Task SumAsync(string tableName, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public async Task SumAsync(string tableName, Field field, QueryGroup where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -2181,7 +2253,8 @@ public async Task SumAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -2204,12 +2277,14 @@ public async Task SumAsync(string tableName, /// The dynamic expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public async Task SumAsync(string tableName, Field field, object where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -2224,7 +2299,8 @@ public async Task SumAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -2247,12 +2323,14 @@ public async Task SumAsync(string tableName, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public async Task SumAsync(string tableName, Field field, QueryField where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -2267,7 +2345,8 @@ public async Task SumAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -2290,12 +2369,14 @@ public async Task SumAsync(string tableName, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public async Task SumAsync(string tableName, Field field, IEnumerable where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -2310,7 +2391,8 @@ public async Task SumAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -2333,12 +2415,14 @@ public async Task SumAsync(string tableName, /// The query expression to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public async Task SumAsync(string tableName, Field field, QueryGroup where = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -2353,7 +2437,8 @@ public async Task SumAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { diff --git a/RepoDb.Core/RepoDb/Operations/DbRepository/SumAll.cs b/RepoDb.Core/RepoDb/Operations/DbRepository/SumAll.cs index 91eeae462..2681e7977 100644 --- a/RepoDb.Core/RepoDb/Operations/DbRepository/SumAll.cs +++ b/RepoDb.Core/RepoDb/Operations/DbRepository/SumAll.cs @@ -2,6 +2,7 @@ using System.Data; using System.Data.Common; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -179,10 +180,12 @@ public TResult SumAll(Expression> field /// The field to be summarized. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public async Task SumAllAsync(Field field, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -196,7 +199,8 @@ public async Task SumAllAsync(Field field, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -217,10 +221,12 @@ public async Task SumAllAsync(Field field, /// The field to be summarized. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public async Task SumAllAsync(Expression> field, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -234,7 +240,8 @@ public async Task SumAllAsync(Expression> commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -256,10 +263,12 @@ public async Task SumAllAsync(Expression> /// The field to be summarized. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public async Task SumAllAsync(Field field, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -273,7 +282,8 @@ public async Task SumAllAsync(Field field, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -295,10 +305,12 @@ public async Task SumAllAsync(Field field, /// The field to be summarized. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public async Task SumAllAsync(Expression> field, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -312,7 +324,8 @@ public async Task SumAllAsync(Expression SumAllAsync(Expression /// Computes the sum value of the target field. /// - /// The transaction to be used. /// The name of the target table. /// The field to be summarized. /// The table hints to be used. + /// The transaction to be used. /// The sum value of the target field. public object SumAll(string tableName, Field field, @@ -373,10 +386,10 @@ public object SumAll(string tableName, /// Computes the sum value of the target field. /// /// The type of the result. - /// The transaction to be used. /// The name of the target table. /// The field to be summarized. /// The table hints to be used. + /// The transaction to be used. /// The sum value of the target field. public TResult SumAll(string tableName, Field field, @@ -416,15 +429,17 @@ public TResult SumAll(string tableName, /// /// Computes the sum value of the target field in an asynchronous way. /// - /// The transaction to be used. /// The name of the target table. /// The field to be summarized. /// The table hints to be used. + /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public async Task SumAllAsync(string tableName, Field field, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -438,7 +453,8 @@ public async Task SumAllAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -456,15 +472,17 @@ public async Task SumAllAsync(string tableName, /// Computes the sum value of the target field in an asynchronous way. /// /// The type of the result. - /// The transaction to be used. /// The name of the target table. /// The field to be summarized. /// The table hints to be used. + /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The sum value of the target field. public async Task SumAllAsync(string tableName, Field field, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -478,7 +496,8 @@ public async Task SumAllAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { diff --git a/RepoDb.Core/RepoDb/Operations/DbRepository/Truncate.cs b/RepoDb.Core/RepoDb/Operations/DbRepository/Truncate.cs index b29e3e6a5..516b81eb6 100644 --- a/RepoDb.Core/RepoDb/Operations/DbRepository/Truncate.cs +++ b/RepoDb.Core/RepoDb/Operations/DbRepository/Truncate.cs @@ -1,6 +1,7 @@ using System; using System.Data; using System.Data.Common; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -84,8 +85,9 @@ public int Truncate(IDbTransaction transaction = null) /// Truncates a table from the database in an asynchronous way. /// /// The type of the data entity. + /// The object to be used during the asynchronous operation. /// The number of rows affected. - public async Task TruncateAsync() + public async Task TruncateAsync(CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -97,7 +99,8 @@ public async Task TruncateAsync() return await connection.TruncateAsync(commandTimeout: CommandTimeout, transaction: null, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -116,8 +119,10 @@ public async Task TruncateAsync() /// /// The type of the data entity. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected. - public async Task TruncateAsync(IDbTransaction transaction = null) + public async Task TruncateAsync(IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -129,7 +134,8 @@ public async Task TruncateAsync(IDbTransaction transaction = null) return await connection.TruncateAsync(commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -219,8 +225,10 @@ public int Truncate(string tableName, /// Truncates a table from the database in an asynchronous way. /// /// The name of the target table. + /// The object to be used during the asynchronous operation. /// The number of rows affected. - public async Task TruncateAsync(string tableName) + public async Task TruncateAsync(string tableName, + CancellationToken cancellationToken = default) { // Create a connection var connection = CreateConnection(); @@ -232,7 +240,8 @@ public async Task TruncateAsync(string tableName) commandTimeout: CommandTimeout, transaction: null, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -251,9 +260,11 @@ public async Task TruncateAsync(string tableName) /// /// The name of the target table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected. public async Task TruncateAsync(string tableName, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = CreateConnection(); @@ -265,7 +276,8 @@ public async Task TruncateAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { diff --git a/RepoDb.Core/RepoDb/Operations/DbRepository/Update.cs b/RepoDb.Core/RepoDb/Operations/DbRepository/Update.cs index 3af90d279..15c698563 100644 --- a/RepoDb.Core/RepoDb/Operations/DbRepository/Update.cs +++ b/RepoDb.Core/RepoDb/Operations/DbRepository/Update.cs @@ -3,6 +3,7 @@ using System.Data; using System.Data.Common; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -661,12 +662,14 @@ public int Update(TEntity entity, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public async Task UpdateAsync(string tableName, TEntity entity, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -682,7 +685,8 @@ public async Task UpdateAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -707,13 +711,15 @@ public async Task UpdateAsync(string tableName, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public async Task UpdateAsync(string tableName, TEntity entity, TWhat what, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -730,7 +736,8 @@ public async Task UpdateAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -754,13 +761,15 @@ public async Task UpdateAsync(string tableName, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public async Task UpdateAsync(string tableName, TEntity entity, object what, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -777,7 +786,8 @@ public async Task UpdateAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -801,13 +811,15 @@ public async Task UpdateAsync(string tableName, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public async Task UpdateAsync(string tableName, TEntity entity, Expression> where, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -824,7 +836,8 @@ public async Task UpdateAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -848,13 +861,15 @@ public async Task UpdateAsync(string tableName, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public async Task UpdateAsync(string tableName, TEntity entity, QueryField where, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -871,7 +886,8 @@ public async Task UpdateAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -895,13 +911,15 @@ public async Task UpdateAsync(string tableName, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public async Task UpdateAsync(string tableName, TEntity entity, IEnumerable where, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -918,7 +936,8 @@ public async Task UpdateAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -942,13 +961,15 @@ public async Task UpdateAsync(string tableName, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public async Task UpdateAsync(string tableName, TEntity entity, QueryGroup where, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -965,7 +986,8 @@ public async Task UpdateAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -987,11 +1009,13 @@ public async Task UpdateAsync(string tableName, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public async Task UpdateAsync(TEntity entity, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1006,7 +1030,8 @@ public async Task UpdateAsync(TEntity entity, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1030,12 +1055,14 @@ public async Task UpdateAsync(TEntity entity, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public async Task UpdateAsync(TEntity entity, TWhat what, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1051,7 +1078,8 @@ public async Task UpdateAsync(TEntity entity, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1074,12 +1102,14 @@ public async Task UpdateAsync(TEntity entity, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public async Task UpdateAsync(TEntity entity, object what, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1095,7 +1125,8 @@ public async Task UpdateAsync(TEntity entity, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1118,12 +1149,14 @@ public async Task UpdateAsync(TEntity entity, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public async Task UpdateAsync(TEntity entity, Expression> where, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1139,7 +1172,8 @@ public async Task UpdateAsync(TEntity entity, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1162,12 +1196,14 @@ public async Task UpdateAsync(TEntity entity, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public async Task UpdateAsync(TEntity entity, QueryField where, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1183,7 +1219,8 @@ public async Task UpdateAsync(TEntity entity, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1206,12 +1243,14 @@ public async Task UpdateAsync(TEntity entity, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public async Task UpdateAsync(TEntity entity, IEnumerable where, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1227,7 +1266,8 @@ public async Task UpdateAsync(TEntity entity, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1250,12 +1290,14 @@ public async Task UpdateAsync(TEntity entity, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public async Task UpdateAsync(TEntity entity, QueryGroup where, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -1271,7 +1313,8 @@ public async Task UpdateAsync(TEntity entity, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1523,12 +1566,14 @@ public int Update(string tableName, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public async Task UpdateAsync(string tableName, object entity, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -1543,7 +1588,8 @@ public async Task UpdateAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1566,13 +1612,15 @@ public async Task UpdateAsync(string tableName, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public async Task UpdateAsync(string tableName, object entity, object where, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -1588,7 +1636,8 @@ public async Task UpdateAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1611,13 +1660,15 @@ public async Task UpdateAsync(string tableName, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public async Task UpdateAsync(string tableName, object entity, QueryField where, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -1633,7 +1684,8 @@ public async Task UpdateAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1656,13 +1708,15 @@ public async Task UpdateAsync(string tableName, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public async Task UpdateAsync(string tableName, object entity, IEnumerable where, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -1678,7 +1732,8 @@ public async Task UpdateAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -1701,13 +1756,15 @@ public async Task UpdateAsync(string tableName, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public async Task UpdateAsync(string tableName, object entity, QueryGroup where, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -1723,7 +1780,8 @@ public async Task UpdateAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { diff --git a/RepoDb.Core/RepoDb/Operations/DbRepository/UpdateAll.cs b/RepoDb.Core/RepoDb/Operations/DbRepository/UpdateAll.cs index e6ad40ed2..cb23be007 100644 --- a/RepoDb.Core/RepoDb/Operations/DbRepository/UpdateAll.cs +++ b/RepoDb.Core/RepoDb/Operations/DbRepository/UpdateAll.cs @@ -3,6 +3,7 @@ using System.Data; using System.Data.Common; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -314,13 +315,15 @@ public int UpdateAll(IEnumerable entities, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public async Task UpdateAllAsync(string tableName, IEnumerable entities, int batchSize = Constant.DefaultBatchOperationSize, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -337,7 +340,8 @@ public async Task UpdateAllAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -362,6 +366,7 @@ public async Task UpdateAllAsync(string tableName, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public async Task UpdateAllAsync(string tableName, IEnumerable entities, @@ -369,7 +374,8 @@ public async Task UpdateAllAsync(string tableName, int batchSize = Constant.DefaultBatchOperationSize, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -387,7 +393,8 @@ public async Task UpdateAllAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -412,6 +419,7 @@ public async Task UpdateAllAsync(string tableName, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public async Task UpdateAllAsync(string tableName, IEnumerable entities, @@ -419,7 +427,8 @@ public async Task UpdateAllAsync(string tableName, int batchSize = Constant.DefaultBatchOperationSize, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -437,7 +446,8 @@ public async Task UpdateAllAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -460,12 +470,14 @@ public async Task UpdateAllAsync(string tableName, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public async Task UpdateAllAsync(IEnumerable entities, int batchSize = Constant.DefaultBatchOperationSize, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -481,7 +493,8 @@ public async Task UpdateAllAsync(IEnumerable entities, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -505,13 +518,15 @@ public async Task UpdateAllAsync(IEnumerable entities, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public async Task UpdateAllAsync(IEnumerable entities, IEnumerable qualifiers, int batchSize = Constant.DefaultBatchOperationSize, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -528,7 +543,8 @@ public async Task UpdateAllAsync(IEnumerable entities, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -552,13 +568,15 @@ public async Task UpdateAllAsync(IEnumerable entities, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public async Task UpdateAllAsync(IEnumerable entities, Expression> qualifiers, int batchSize = Constant.DefaultBatchOperationSize, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -575,7 +593,8 @@ public async Task UpdateAllAsync(IEnumerable entities, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -747,13 +766,15 @@ public int UpdateAll(string tableName, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public async Task UpdateAllAsync(string tableName, IEnumerable entities, int batchSize = Constant.DefaultBatchOperationSize, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -769,7 +790,8 @@ public async Task UpdateAllAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -793,6 +815,7 @@ public async Task UpdateAllAsync(string tableName, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public async Task UpdateAllAsync(string tableName, IEnumerable entities, @@ -800,7 +823,8 @@ public async Task UpdateAllAsync(string tableName, int batchSize = Constant.DefaultBatchOperationSize, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -817,7 +841,8 @@ public async Task UpdateAllAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { @@ -841,6 +866,7 @@ public async Task UpdateAllAsync(string tableName, /// The mapping list of objects to be used. /// The table hints to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of affected rows during the update process. public async Task UpdateAllAsync(string tableName, IEnumerable entities, @@ -848,7 +874,8 @@ public async Task UpdateAllAsync(string tableName, int batchSize = Constant.DefaultBatchOperationSize, IEnumerable fields = null, string hints = null, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? CreateConnection()); @@ -865,7 +892,8 @@ public async Task UpdateAllAsync(string tableName, commandTimeout: CommandTimeout, transaction: transaction, trace: Trace, - statementBuilder: StatementBuilder); + statementBuilder: StatementBuilder, + cancellationToken: cancellationToken); } catch { diff --git a/RepoDb.Core/RepoDb/QueryMultipleExtractor.cs b/RepoDb.Core/RepoDb/QueryMultipleExtractor.cs index 91901fcfd..490df8e5a 100644 --- a/RepoDb.Core/RepoDb/QueryMultipleExtractor.cs +++ b/RepoDb.Core/RepoDb/QueryMultipleExtractor.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.Data.Common; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -23,10 +24,13 @@ public sealed class QueryMultipleExtractor : IDisposable /// Creates a new instance of class. /// /// The to be extracted. - internal QueryMultipleExtractor(DbDataReader reader) + /// The object to be used during the asynchronous operation. + internal QueryMultipleExtractor(DbDataReader reader, + CancellationToken cancellationToken = default) { this.reader = reader; Position = 0; + CancellationToken = cancellationToken; } /// @@ -42,6 +46,11 @@ public void Dispose() => /// public int Position { get; private set; } + /// + /// Gets the instance of the currently in used. + /// + public CancellationToken CancellationToken { get; private set; } + #endregion #region Extract @@ -74,7 +83,7 @@ public IEnumerable Extract(bool isMoveToNextResult = true) public async Task> ExtractAsync(bool isMoveToNextResult = true) where TEntity : class { - var result = (await DataReader.ToEnumerableAsync(reader)).AsList(); + var result = (await DataReader.ToEnumerableAsync(reader, cancellationToken: CancellationToken)).AsList(); if (isMoveToNextResult) { await NextResultAsync(); @@ -108,7 +117,7 @@ public IEnumerable Extract(bool isMoveToNextResult = true) /// An enumerable of extracted data entity. public async Task> ExtractAsync(bool isMoveToNextResult = true) { - var result = (await DataReader.ToEnumerableAsync(reader)).AsList(); + var result = (await DataReader.ToEnumerableAsync(reader, cancellationToken: CancellationToken)).AsList(); if (isMoveToNextResult) { await NextResultAsync(); @@ -153,7 +162,7 @@ public TResult Scalar(bool isMoveToNextResult = true) public async Task ScalarAsync(bool isMoveToNextResult = true) { var value = default(TResult); - if (await reader.ReadAsync()) + if (await reader.ReadAsync(CancellationToken)) { value = Converter.ToType(reader[0]); } @@ -202,7 +211,7 @@ public bool NextResult() => /// True if there are more result sets; otherwise false. /// public async Task NextResultAsync() => - (Position = await reader.NextResultAsync() ? Position + 1 : -1) >= 0; + (Position = await reader.NextResultAsync(CancellationToken) ? Position + 1 : -1) >= 0; #endregion } diff --git a/RepoDb.Core/RepoDb/Reflection/Compiler/Compiler.cs b/RepoDb.Core/RepoDb/Reflection/Compiler/Compiler.cs index ef4367810..79eaa871c 100644 --- a/RepoDb.Core/RepoDb/Reflection/Compiler/Compiler.cs +++ b/RepoDb.Core/RepoDb/Reflection/Compiler/Compiler.cs @@ -299,52 +299,6 @@ internal static ParameterInfo GetPropertyHandlerSetParameter(object handlerInsta internal static ParameterInfo GetPropertyHandlerSetParameter(MethodInfo setMethod) => setMethod?.GetParameters()?.First(); - /// - /// - /// - /// - /// - /// - /// - /// - /// - internal static IEnumerable GetDbFields(IDbConnection connection, - string tableName, - string connectionString, - IDbTransaction transaction, - bool enableValidation) - { - // If the connection is open, probably, there is already an open DbDataReader object - if (connection.State != ConnectionState.Open) - { - return DbFieldCache.Get(connection, tableName, transaction, enableValidation); - } - return null; - } - - /// - /// - /// - /// - /// - /// - /// - /// - /// - internal static async Task> GetDbFieldsAsync(IDbConnection connection, - string tableName, - string connectionString, - IDbTransaction transaction, - bool enableValidation) - { - // If the connection is open, probably, there is already an open DbDataReader object - if (connection.State != ConnectionState.Open) - { - return await DbFieldCache.GetAsync(connection, tableName, transaction, enableValidation); - } - return null; - } - /// /// /// diff --git a/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/Microsoft.Data.SqlClient/BaseRepository/BulkDelete.cs b/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/Microsoft.Data.SqlClient/BaseRepository/BulkDelete.cs index 2c243bb7d..f69069b99 100644 --- a/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/Microsoft.Data.SqlClient/BaseRepository/BulkDelete.cs +++ b/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/Microsoft.Data.SqlClient/BaseRepository/BulkDelete.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -126,20 +127,23 @@ public static int BulkDelete(this BaseRepositoryThe size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static Task BulkDeleteAsync(this BaseRepository repository, IEnumerable primaryKeys, string hints = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { return repository.DbRepository.BulkDeleteAsync(primaryKeys: primaryKeys, hints: hints, batchSize: batchSize, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -155,6 +159,7 @@ public static Task BulkDeleteAsync(this BaseRepositoryThe size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static Task BulkDeleteAsync(this BaseRepository repository, IEnumerable entities, @@ -164,7 +169,8 @@ public static Task BulkDeleteAsync(this BaseRepository(entities: entities, @@ -174,7 +180,8 @@ public static Task BulkDeleteAsync(this BaseRepository @@ -191,6 +198,7 @@ public static Task BulkDeleteAsync(this BaseRepositoryThe size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static Task BulkDeleteAsync(this BaseRepository repository, string tableName, @@ -201,7 +209,8 @@ public static Task BulkDeleteAsync(this BaseRepository(tableName: tableName, @@ -212,7 +221,8 @@ public static Task BulkDeleteAsync(this BaseRepository(this BaseRepositoryThe flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. This argument will only be used if the 'isReturnIdentity' argument is 'true'. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static Task BulkInsertAsync(this BaseRepository repository, IEnumerable entities, @@ -110,7 +112,8 @@ public static Task BulkInsertAsync(this BaseRepository(entities: entities, @@ -120,7 +123,8 @@ public static Task BulkInsertAsync(this BaseRepository @@ -137,6 +141,7 @@ public static Task BulkInsertAsync(this BaseRepositoryThe flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. This argument will only be used if the 'isReturnIdentity' argument is 'true'. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static Task BulkInsertAsync(this BaseRepository repository, string tableName, @@ -147,7 +152,8 @@ public static Task BulkInsertAsync(this BaseRepository(tableName: tableName, @@ -158,7 +164,8 @@ public static Task BulkInsertAsync(this BaseRepository(this BaseRepository /// The flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static Task BulkMergeAsync(this BaseRepository repository, IEnumerable entities, @@ -120,7 +122,8 @@ public static Task BulkMergeAsync(this BaseRepository(entities: entities, @@ -131,7 +134,8 @@ public static Task BulkMergeAsync(this BaseRepository @@ -149,6 +153,7 @@ public static Task BulkMergeAsync(this BaseRepositoryThe flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static Task BulkMergeAsync(this BaseRepository repository, string tableName, @@ -160,7 +165,8 @@ public static Task BulkMergeAsync(this BaseRepository(tableName: tableName, @@ -172,7 +178,8 @@ public static Task BulkMergeAsync(this BaseRepository(this BaseRepositoryThe size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static Task BulkUpdateAsync(this BaseRepository repository, IEnumerable entities, @@ -112,7 +114,8 @@ public static Task BulkUpdateAsync(this BaseRepository(entities: entities, @@ -122,7 +125,8 @@ public static Task BulkUpdateAsync(this BaseRepository @@ -139,6 +143,7 @@ public static Task BulkUpdateAsync(this BaseRepositoryThe size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static Task BulkUpdateAsync(this BaseRepository repository, string tableName, @@ -149,7 +154,8 @@ public static Task BulkUpdateAsync(this BaseRepository(tableName: tableName, @@ -160,7 +166,8 @@ public static Task BulkUpdateAsync(this BaseRepository repository, /// The size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkDeleteAsync(this DbRepository repository, IEnumerable primaryKeys, string hints = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -520,7 +523,8 @@ public static async Task BulkDeleteAsync(this DbRepository BulkDeleteAsync(this DbRepositoryThe size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkDeleteAsync(this DbRepository repository, IEnumerable entities, @@ -562,7 +567,8 @@ public static async Task BulkDeleteAsync(this DbRepository BulkDeleteAsync(this DbRepository BulkDeleteAsync(this DbRepositoryThe size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkDeleteAsync(this DbRepository repository, string tableName, @@ -623,7 +631,8 @@ public static async Task BulkDeleteAsync(this DbRepository BulkDeleteAsync(this DbRepository BulkDeleteAsync(this DbRepositoryThe size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkDeleteAsync(this DbRepository repository, DbDataReader reader, @@ -683,7 +694,8 @@ public static async Task BulkDeleteAsync(this DbRepository BulkDeleteAsync(this DbRepository BulkDeleteAsync(this DbRepositoryThe size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkDeleteAsync(this DbRepository repository, DataTable dataTable, @@ -744,7 +758,8 @@ public static async Task BulkDeleteAsync(this DbRepository BulkDeleteAsync(this DbRepository BulkDeleteAsync(this DbRepositoryThe size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkDeleteAsync(this DbRepository repository, string tableName, @@ -803,7 +820,8 @@ public static async Task BulkDeleteAsync(this DbRepository r string hints = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? repository.CreateConnection()); @@ -817,7 +835,8 @@ public static async Task BulkDeleteAsync(this DbRepository r bulkCopyTimeout: repository.CommandTimeout, batchSize: batchSize, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } catch { @@ -850,6 +869,7 @@ public static async Task BulkDeleteAsync(this DbRepository r /// The size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkDeleteAsync(this DbRepository repository, string tableName, @@ -860,7 +880,8 @@ public static async Task BulkDeleteAsync(this DbRepository r string hints = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? repository.CreateConnection()); @@ -877,7 +898,8 @@ public static async Task BulkDeleteAsync(this DbRepository r bulkCopyTimeout: repository.CommandTimeout, batchSize: batchSize, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } catch { @@ -911,6 +933,7 @@ public static async Task BulkDeleteAsync(this DbRepository r /// The size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkDeleteAsync(this DbRepository repository, string tableName, @@ -922,7 +945,8 @@ public static async Task BulkDeleteAsync(this DbRepository r string hints = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? repository.CreateConnection()); @@ -940,7 +964,8 @@ public static async Task BulkDeleteAsync(this DbRepository r bulkCopyTimeout: repository.CommandTimeout, batchSize: batchSize, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } catch { diff --git a/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/Microsoft.Data.SqlClient/DbRepository/BulkInsert.cs b/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/Microsoft.Data.SqlClient/DbRepository/BulkInsert.cs index dc3a40ace..205225619 100644 --- a/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/Microsoft.Data.SqlClient/DbRepository/BulkInsert.cs +++ b/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/Microsoft.Data.SqlClient/DbRepository/BulkInsert.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Data; using System.Data.Common; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -382,6 +383,7 @@ public static int BulkInsert(this DbRepository repository, /// The flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. This argument will only be used if the 'isReturnIdentity' argument is 'true'. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkInsertAsync(this DbRepository repository, IEnumerable entities, @@ -391,7 +393,8 @@ public static async Task BulkInsertAsync(this DbRepository BulkInsertAsync(this DbRepository BulkInsertAsync(this DbRepositoryThe flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. This argument will only be used if the 'isReturnIdentity' argument is 'true'. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkInsertAsync(this DbRepository repository, string tableName, @@ -452,7 +457,8 @@ public static async Task BulkInsertAsync(this DbRepository BulkInsertAsync(this DbRepository BulkInsertAsync(this DbRepositoryThe bulk-copy options to be used. /// The size per batch to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkInsertAsync(this DbRepository repository, DbDataReader reader, IEnumerable mappings = null, SqlBulkCopyOptions? options = null, int? batchSize = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -520,7 +529,8 @@ public static async Task BulkInsertAsync(this DbRepository BulkInsertAsync(this DbRepositoryThe bulk-copy options to be used. /// The size per batch to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkInsertAsync(this DbRepository repository, string tableName, @@ -561,7 +572,8 @@ public static async Task BulkInsertAsync(this DbRepository r IEnumerable mappings = null, SqlBulkCopyOptions? options = null, int? batchSize = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? repository.CreateConnection()); @@ -575,7 +587,8 @@ public static async Task BulkInsertAsync(this DbRepository r options: options, bulkCopyTimeout: repository.CommandTimeout, batchSize: batchSize, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } catch { @@ -609,6 +622,7 @@ public static async Task BulkInsertAsync(this DbRepository r /// The flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. This argument will only be used if the 'isReturnIdentity' argument is 'true'. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkInsertAsync(this DbRepository repository, DataTable dataTable, @@ -619,7 +633,8 @@ public static async Task BulkInsertAsync(this DbRepository BulkInsertAsync(this DbRepository BulkInsertAsync(this DbRepositoryThe flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. This argument will only be used if the 'isReturnIdentity' argument is 'true'. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkInsertAsync(this DbRepository repository, string tableName, @@ -682,7 +699,8 @@ public static async Task BulkInsertAsync(this DbRepository r int? batchSize = null, bool? isReturnIdentity = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? repository.CreateConnection()); @@ -700,7 +718,8 @@ public static async Task BulkInsertAsync(this DbRepository r batchSize: batchSize, isReturnIdentity: isReturnIdentity, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } catch { diff --git a/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/Microsoft.Data.SqlClient/DbRepository/BulkMerge.cs b/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/Microsoft.Data.SqlClient/DbRepository/BulkMerge.cs index 040458b80..f6214b0a9 100644 --- a/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/Microsoft.Data.SqlClient/DbRepository/BulkMerge.cs +++ b/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/Microsoft.Data.SqlClient/DbRepository/BulkMerge.cs @@ -5,6 +5,7 @@ using System.Data; using System.Data.Common; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -415,6 +416,7 @@ public static int BulkMerge(this DbRepository repository, /// The flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkMergeAsync(this DbRepository repository, IEnumerable entities, @@ -425,7 +427,8 @@ public static async Task BulkMergeAsync(this DbRepository BulkMergeAsync(this DbRepository BulkMergeAsync(this DbRepositoryThe flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkMergeAsync(this DbRepository repository, string tableName, @@ -489,7 +494,8 @@ public static async Task BulkMergeAsync(this DbRepository BulkMergeAsync(this DbRepository BulkMergeAsync(this DbRepositoryThe size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkMergeAsync(this DbRepository repository, DbDataReader reader, @@ -550,7 +558,8 @@ public static async Task BulkMergeAsync(this DbRepository BulkMergeAsync(this DbRepository BulkMergeAsync(this DbRepositoryThe size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkMergeAsync(this DbRepository repository, string tableName, @@ -614,7 +625,8 @@ public static async Task BulkMergeAsync(this DbRepository re string hints = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? repository.CreateConnection()); @@ -631,7 +643,8 @@ public static async Task BulkMergeAsync(this DbRepository re bulkCopyTimeout: repository.CommandTimeout, batchSize: batchSize, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } catch { @@ -666,6 +679,7 @@ public static async Task BulkMergeAsync(this DbRepository re /// The flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkMergeAsync(this DbRepository repository, DataTable dataTable, @@ -677,7 +691,8 @@ public static async Task BulkMergeAsync(this DbRepository BulkMergeAsync(this DbRepository BulkMergeAsync(this DbRepositoryThe flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkMergeAsync(this DbRepository repository, string tableName, @@ -743,7 +760,8 @@ public static async Task BulkMergeAsync(this DbRepository re int? batchSize = null, bool? isReturnIdentity = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? repository.CreateConnection()); @@ -762,7 +780,8 @@ public static async Task BulkMergeAsync(this DbRepository re batchSize: batchSize, isReturnIdentity: isReturnIdentity, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } catch { diff --git a/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/Microsoft.Data.SqlClient/DbRepository/BulkUpdate.cs b/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/Microsoft.Data.SqlClient/DbRepository/BulkUpdate.cs index 5cdcbae99..a1c079770 100644 --- a/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/Microsoft.Data.SqlClient/DbRepository/BulkUpdate.cs +++ b/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/Microsoft.Data.SqlClient/DbRepository/BulkUpdate.cs @@ -5,6 +5,7 @@ using System.Data; using System.Data.Common; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -402,6 +403,7 @@ public static int BulkUpdate(this DbRepository repository, /// The size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkUpdateAsync(this DbRepository repository, IEnumerable entities, @@ -411,7 +413,8 @@ public static async Task BulkUpdateAsync(this DbRepository BulkUpdateAsync(this DbRepository BulkUpdateAsync(this DbRepositoryThe size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkUpdateAsync(this DbRepository repository, string tableName, @@ -472,7 +477,8 @@ public static async Task BulkUpdateAsync(this DbRepository BulkUpdateAsync(this DbRepository BulkUpdateAsync(this DbRepositoryThe size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkUpdateAsync(this DbRepository repository, DbDataReader reader, @@ -532,7 +540,8 @@ public static async Task BulkUpdateAsync(this DbRepository BulkUpdateAsync(this DbRepository BulkUpdateAsync(this DbRepositoryThe size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkUpdateAsync(this DbRepository repository, string tableName, @@ -596,7 +607,8 @@ public static async Task BulkUpdateAsync(this DbRepository r string hints = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? repository.CreateConnection()); @@ -613,7 +625,8 @@ public static async Task BulkUpdateAsync(this DbRepository r bulkCopyTimeout: repository.CommandTimeout, batchSize: batchSize, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } catch { @@ -647,6 +660,7 @@ public static async Task BulkUpdateAsync(this DbRepository r /// The size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkUpdateAsync(this DbRepository repository, DataTable dataTable, @@ -657,7 +671,8 @@ public static async Task BulkUpdateAsync(this DbRepository BulkUpdateAsync(this DbRepository BulkUpdateAsync(this DbRepositoryThe size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkUpdateAsync(this DbRepository repository, string tableName, @@ -720,7 +737,8 @@ public static async Task BulkUpdateAsync(this DbRepository r string hints = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? repository.CreateConnection()); @@ -738,7 +756,8 @@ public static async Task BulkUpdateAsync(this DbRepository r bulkCopyTimeout: repository.CommandTimeout, batchSize: batchSize, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } catch { diff --git a/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/Microsoft.Data.SqlClient/SqlConnection/BulkDelete.cs b/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/Microsoft.Data.SqlClient/SqlConnection/BulkDelete.cs index 2287dc39a..80862c94e 100644 --- a/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/Microsoft.Data.SqlClient/SqlConnection/BulkDelete.cs +++ b/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/Microsoft.Data.SqlClient/SqlConnection/BulkDelete.cs @@ -6,6 +6,7 @@ using System.Data.Common; using System.Linq; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -354,6 +355,7 @@ public static int BulkDelete(this SqlConnection connection, /// The size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkDeleteAsync(this SqlConnection connection, IEnumerable primaryKeys, @@ -361,7 +363,8 @@ public static async Task BulkDeleteAsync(this SqlConnection connec int? bulkCopyTimeout = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { return await BulkDeleteAsyncInternal(connection: connection, @@ -371,7 +374,8 @@ public static async Task BulkDeleteAsync(this SqlConnection connec bulkCopyTimeout: bulkCopyTimeout, batchSize: batchSize, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -388,6 +392,7 @@ public static async Task BulkDeleteAsync(this SqlConnection connec /// The size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkDeleteAsync(this SqlConnection connection, IEnumerable entities, @@ -398,12 +403,13 @@ public static async Task BulkDeleteAsync(this SqlConnection connec int? bulkCopyTimeout = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { using (var reader = new DataEntityDataReader(entities)) { - await reader.InitializeAsync(); + await reader.InitializeAsync(cancellationToken); return await BulkDeleteAsyncInternal(connection: connection, tableName: ClassMappedNameCache.Get(), reader: reader, @@ -414,7 +420,8 @@ public static async Task BulkDeleteAsync(this SqlConnection connec bulkCopyTimeout: bulkCopyTimeout, batchSize: batchSize, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } } @@ -433,6 +440,7 @@ public static async Task BulkDeleteAsync(this SqlConnection connec /// The size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkDeleteAsync(this SqlConnection connection, string tableName, @@ -444,12 +452,13 @@ public static async Task BulkDeleteAsync(this SqlConnection connec int? bulkCopyTimeout = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { using (var reader = new DataEntityDataReader(entities)) { - await reader.InitializeAsync(); + await reader.InitializeAsync(cancellationToken); return await BulkDeleteAsyncInternal(connection: connection, tableName: tableName, reader: reader, @@ -460,7 +469,8 @@ public static async Task BulkDeleteAsync(this SqlConnection connec bulkCopyTimeout: bulkCopyTimeout, batchSize: batchSize, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } } @@ -478,6 +488,7 @@ public static async Task BulkDeleteAsync(this SqlConnection connec /// The size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkDeleteAsync(this SqlConnection connection, DbDataReader reader, @@ -488,7 +499,8 @@ public static async Task BulkDeleteAsync(this SqlConnection connec int? bulkCopyTimeout = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { return await BulkDeleteAsyncInternal(connection: connection, @@ -501,7 +513,8 @@ public static async Task BulkDeleteAsync(this SqlConnection connec bulkCopyTimeout: bulkCopyTimeout, batchSize: batchSize, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -519,6 +532,7 @@ public static async Task BulkDeleteAsync(this SqlConnection connec /// The size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkDeleteAsync(this SqlConnection connection, DataTable dataTable, @@ -530,7 +544,8 @@ public static async Task BulkDeleteAsync(this SqlConnection connec int? bulkCopyTimeout = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { return await BulkDeleteAsyncInternal(connection: connection, @@ -544,7 +559,8 @@ public static async Task BulkDeleteAsync(this SqlConnection connec bulkCopyTimeout: bulkCopyTimeout, batchSize: batchSize, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } #endregion @@ -562,6 +578,7 @@ public static async Task BulkDeleteAsync(this SqlConnection connec /// The size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkDeleteAsync(this SqlConnection connection, string tableName, @@ -570,7 +587,8 @@ public static async Task BulkDeleteAsync(this SqlConnection connection, int? bulkCopyTimeout = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) { return await BulkDeleteAsyncInternal(connection: connection, tableName: tableName, @@ -579,7 +597,8 @@ public static async Task BulkDeleteAsync(this SqlConnection connection, bulkCopyTimeout: bulkCopyTimeout, batchSize: batchSize, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -596,6 +615,7 @@ public static async Task BulkDeleteAsync(this SqlConnection connection, /// The size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkDeleteAsync(this SqlConnection connection, string tableName, @@ -607,7 +627,8 @@ public static async Task BulkDeleteAsync(this SqlConnection connection, int? bulkCopyTimeout = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) { return await BulkDeleteAsyncInternal(connection: connection, tableName: tableName, @@ -619,7 +640,8 @@ public static async Task BulkDeleteAsync(this SqlConnection connection, bulkCopyTimeout: bulkCopyTimeout, batchSize: batchSize, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -637,6 +659,7 @@ public static async Task BulkDeleteAsync(this SqlConnection connection, /// The size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkDeleteAsync(this SqlConnection connection, string tableName, @@ -649,7 +672,8 @@ public static async Task BulkDeleteAsync(this SqlConnection connection, int? bulkCopyTimeout = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) { return await BulkDeleteAsyncInternal(connection: connection, tableName: tableName, @@ -662,7 +686,8 @@ public static async Task BulkDeleteAsync(this SqlConnection connection, bulkCopyTimeout: bulkCopyTimeout, batchSize: batchSize, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } #endregion @@ -1212,6 +1237,7 @@ internal static int BulkDeleteInternal(SqlConnection connection, /// The size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. internal static async Task BulkDeleteAsyncInternal(SqlConnection connection, string tableName, @@ -1220,7 +1246,8 @@ internal static async Task BulkDeleteAsyncInternal(SqlConnection connection int? bulkCopyTimeout = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) { // Variables var dbSetting = connection.GetDbSetting(); @@ -1231,7 +1258,7 @@ internal static async Task BulkDeleteAsyncInternal(SqlConnection connection if (transaction == null) { // Add the transaction if not present - transaction = (SqlTransaction)(await connection.EnsureOpenAsync()).BeginTransaction(); + transaction = (SqlTransaction)(await connection.EnsureOpenAsync(cancellationToken)).BeginTransaction(); } else { @@ -1254,7 +1281,7 @@ internal static async Task BulkDeleteAsyncInternal(SqlConnection connection try { // Get the DB Fields - var dbFields = await DbFieldCache.GetAsync(connection, tableName, transaction, true); + var dbFields = await DbFieldCache.GetAsync(connection, tableName, transaction, true, cancellationToken); // Variables needed var primaryDbField = dbFields?.FirstOrDefault(dbField => dbField.IsPrimary); @@ -1273,7 +1300,7 @@ internal static async Task BulkDeleteAsyncInternal(SqlConnection connection tempTableName, primaryOrIdentityField.AsEnumerable(), dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); // Do the bulk insertion first using (var dataTable = CreateDataTableWithSingleColumn(primaryOrIdentityField, primaryKeys)) @@ -1289,14 +1316,15 @@ await BulkInsertAsyncInternal(connection, options: options, bulkCopyTimeout: bulkCopyTimeout, batchSize: batchSize, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } // Create the clustered index sql = GetCreateTemporaryTableClusteredIndexSqlText(tempTableName, primaryOrIdentityField.AsEnumerable(), dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); // Delete the actual delete sql = GetBulkDeleteSqlText(tableName, @@ -1304,11 +1332,11 @@ await BulkInsertAsyncInternal(connection, primaryOrIdentityField.AsEnumerable(), hints, dbSetting); - result = connection.ExecuteNonQuery(sql, commandTimeout: bulkCopyTimeout, transaction: transaction); + result = await connection.ExecuteNonQueryAsync(sql, commandTimeout: bulkCopyTimeout, transaction: transaction, cancellationToken: cancellationToken); // Drop the table after used sql = GetDropTemporaryTableSqlText(tempTableName, dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); // Commit the transaction if (hasTransaction == false) @@ -1354,6 +1382,7 @@ await BulkInsertAsyncInternal(connection, /// The size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. internal static async Task BulkDeleteAsyncInternal(SqlConnection connection, string tableName, @@ -1365,7 +1394,8 @@ internal static async Task BulkDeleteAsyncInternal(SqlConnection connection int? bulkCopyTimeout = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) { // Variables var dbSetting = connection.GetDbSetting(); @@ -1376,7 +1406,7 @@ internal static async Task BulkDeleteAsyncInternal(SqlConnection connection if (transaction == null) { // Add the transaction if not present - transaction = (SqlTransaction)(await connection.EnsureOpenAsync()).BeginTransaction(); + transaction = (SqlTransaction)(await connection.EnsureOpenAsync(cancellationToken)).BeginTransaction(); } else { @@ -1399,7 +1429,7 @@ internal static async Task BulkDeleteAsyncInternal(SqlConnection connection try { // Get the DB Fields - var dbFields = await DbFieldCache.GetAsync(connection, tableName, transaction, true); + var dbFields = await DbFieldCache.GetAsync(connection, tableName, transaction, true, cancellationToken); // Variables needed var readerFields = Enumerable.Range(0, reader.FieldCount) @@ -1449,7 +1479,7 @@ internal static async Task BulkDeleteAsyncInternal(SqlConnection connection tempTableName, fields, dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); // Set the options to KeepIdentity if needed if (options == null && identityDbField?.IsIdentity == true && @@ -1471,24 +1501,25 @@ internal static async Task BulkDeleteAsyncInternal(SqlConnection connection fields?.Any(field => string.Equals(field.Name, dbField.Name, StringComparison.OrdinalIgnoreCase)) == true); // Do the bulk insertion first - await BulkInsertAsyncInternal(connection, - tempTableName, - reader, - filteredDbFields, - mappings, - options, - null, + await BulkInsertAsyncInternal(connection: connection, + tableName: tempTableName, + reader: reader, + dbFields: filteredDbFields, + mappings: mappings, + options: options, + hints: hints, bulkCopyTimeout, batchSize, - false, - false, - transaction); + isReturnIdentity: false, + usePhysicalPseudoTempTable: false, + transaction: transaction, + cancellationToken: cancellationToken); // Create the clustered index sql = GetCreateTemporaryTableClusteredIndexSqlText(tempTableName, qualifiers, dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); // Delete the actual delete sql = GetBulkDeleteSqlText(tableName, @@ -1496,11 +1527,11 @@ await BulkInsertAsyncInternal(connection, qualifiers, hints, dbSetting); - result = await connection.ExecuteNonQueryAsync(sql, commandTimeout: bulkCopyTimeout, transaction: transaction); + result = await connection.ExecuteNonQueryAsync(sql, commandTimeout: bulkCopyTimeout, transaction: transaction, cancellationToken: cancellationToken); // Drop the table after used sql = GetDropTemporaryTableSqlText(tempTableName, dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); // Commit the transaction if (hasTransaction == false) @@ -1547,6 +1578,7 @@ await BulkInsertAsyncInternal(connection, /// The size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. internal static async Task BulkDeleteAsyncInternal(SqlConnection connection, string tableName, @@ -1559,7 +1591,8 @@ internal static async Task BulkDeleteAsyncInternal(SqlConnection connection int? bulkCopyTimeout = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) { // Variables var dbSetting = connection.GetDbSetting(); @@ -1570,7 +1603,7 @@ internal static async Task BulkDeleteAsyncInternal(SqlConnection connection if (transaction == null) { // Add the transaction if not present - transaction = (SqlTransaction)(await connection.EnsureOpenAsync()).BeginTransaction(); + transaction = (SqlTransaction)(await connection.EnsureOpenAsync(cancellationToken)).BeginTransaction(); } else { @@ -1593,7 +1626,7 @@ internal static async Task BulkDeleteAsyncInternal(SqlConnection connection try { // Get the DB Fields - var dbFields = await DbFieldCache.GetAsync(connection, tableName, transaction, true); + var dbFields = await DbFieldCache.GetAsync(connection, tableName, transaction, true, cancellationToken); // Variables needed var tableFields = Enumerable.Range(0, dataTable.Columns.Count) @@ -1643,7 +1676,7 @@ internal static async Task BulkDeleteAsyncInternal(SqlConnection connection tempTableName, fields, dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); // Set the options to KeepIdentity if needed if (options == null && identityDbField?.IsIdentity == true && @@ -1665,25 +1698,26 @@ internal static async Task BulkDeleteAsyncInternal(SqlConnection connection fields?.Any(field => string.Equals(field.Name, dbField.Name, StringComparison.OrdinalIgnoreCase)) == true); // Do the bulk insertion first - await BulkInsertAsyncInternal(connection, - tempTableName, - dataTable, - rowState, - filteredDbFields, - mappings, - options, - null, + await BulkInsertAsyncInternal(connection: connection, + tableName: tempTableName, + dataTable: dataTable, + rowState: rowState, + dbFields: filteredDbFields, + mappings: mappings, + options: options, + hints: hints, bulkCopyTimeout, batchSize, - false, - false, - transaction); + isReturnIdentity: false, + usePhysicalPseudoTempTable: false, + transaction: transaction, + cancellationToken: cancellationToken); // Create the clustered index sql = GetCreateTemporaryTableClusteredIndexSqlText(tempTableName, qualifiers, dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); // Delete the actual delete sql = GetBulkDeleteSqlText(tableName, @@ -1691,11 +1725,11 @@ await BulkInsertAsyncInternal(connection, qualifiers, hints, dbSetting); - result = await connection.ExecuteNonQueryAsync(sql, commandTimeout: bulkCopyTimeout, transaction: transaction); + result = await connection.ExecuteNonQueryAsync(sql, commandTimeout: bulkCopyTimeout, transaction: transaction, cancellationToken: cancellationToken); // Drop the table after used sql = GetDropTemporaryTableSqlText(tempTableName, dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); // Commit the transaction if (hasTransaction == false) diff --git a/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/Microsoft.Data.SqlClient/SqlConnection/BulkInsert.cs b/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/Microsoft.Data.SqlClient/SqlConnection/BulkInsert.cs index db44f97ce..1a6c76aa1 100644 --- a/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/Microsoft.Data.SqlClient/SqlConnection/BulkInsert.cs +++ b/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/Microsoft.Data.SqlClient/SqlConnection/BulkInsert.cs @@ -7,6 +7,7 @@ using System.Data; using System.Data.Common; using System.Linq; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -276,6 +277,7 @@ public static int BulkInsert(this SqlConnection connection, /// The flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. This argument will only be used if the 'isReturnIdentity' argument is 'true'. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkInsertAsync(this SqlConnection connection, IEnumerable entities, @@ -286,7 +288,8 @@ public static async Task BulkInsertAsync(this SqlConnection connec int? batchSize = null, bool? isReturnIdentity = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { return await BulkInsertAsyncInternal(connection: connection, @@ -300,7 +303,8 @@ public static async Task BulkInsertAsync(this SqlConnection connec batchSize: batchSize, isReturnIdentity: isReturnIdentity, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -318,6 +322,7 @@ public static async Task BulkInsertAsync(this SqlConnection connec /// The flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. This argument will only be used if the 'isReturnIdentity' argument is 'true'. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkInsertAsync(this SqlConnection connection, string tableName, @@ -329,7 +334,8 @@ public static async Task BulkInsertAsync(this SqlConnection connec int? batchSize = null, bool? isReturnIdentity = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { return await BulkInsertAsyncInternal(connection: connection, @@ -343,7 +349,8 @@ public static async Task BulkInsertAsync(this SqlConnection connec batchSize: batchSize, isReturnIdentity: isReturnIdentity, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -357,6 +364,7 @@ public static async Task BulkInsertAsync(this SqlConnection connec /// The timeout in seconds to be used. /// The size per batch to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkInsertAsync(this SqlConnection connection, DbDataReader reader, @@ -364,7 +372,8 @@ public static async Task BulkInsertAsync(this SqlConnection connec SqlBulkCopyOptions? options = null, int? bulkCopyTimeout = null, int? batchSize = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { return await BulkInsertAsyncInternal(connection: connection, @@ -375,7 +384,8 @@ public static async Task BulkInsertAsync(this SqlConnection connec options: options, bulkCopyTimeout: bulkCopyTimeout, batchSize: batchSize, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } #endregion @@ -393,6 +403,7 @@ public static async Task BulkInsertAsync(this SqlConnection connec /// The timeout in seconds to be used. /// The size per batch to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkInsertAsync(this SqlConnection connection, string tableName, @@ -401,7 +412,8 @@ public static async Task BulkInsertAsync(this SqlConnection connection, SqlBulkCopyOptions? options = null, int? bulkCopyTimeout = null, int? batchSize = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) { return await BulkInsertAsyncInternal(connection: connection, tableName: tableName, @@ -411,7 +423,8 @@ public static async Task BulkInsertAsync(this SqlConnection connection, options: options, bulkCopyTimeout: bulkCopyTimeout, batchSize: batchSize, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -429,6 +442,7 @@ public static async Task BulkInsertAsync(this SqlConnection connection, /// The flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. This argument will only be used if the 'isReturnIdentity' argument is 'true'. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkInsertAsync(this SqlConnection connection, DataTable dataTable, @@ -440,7 +454,8 @@ public static async Task BulkInsertAsync(this SqlConnection connec int? batchSize = null, bool? isReturnIdentity = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { return await BulkInsertAsyncInternal(connection: connection, @@ -455,7 +470,8 @@ public static async Task BulkInsertAsync(this SqlConnection connec batchSize: batchSize, isReturnIdentity: isReturnIdentity, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -473,6 +489,7 @@ public static async Task BulkInsertAsync(this SqlConnection connec /// The flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. This argument will only be used if the 'isReturnIdentity' argument is 'true'. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkInsertAsync(this SqlConnection connection, string tableName, @@ -485,7 +502,8 @@ public static async Task BulkInsertAsync(this SqlConnection connection, int? batchSize = null, bool? isReturnIdentity = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) { return await BulkInsertAsyncInternal(connection: connection, tableName: tableName, @@ -499,7 +517,8 @@ public static async Task BulkInsertAsync(this SqlConnection connection, batchSize: batchSize, isReturnIdentity: isReturnIdentity, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } #endregion @@ -1179,6 +1198,7 @@ internal static int BulkInsertInternal(SqlConnection connection, /// The flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. This argument will only be used if the 'isReturnIdentity' argument is 'true'. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. internal static async Task BulkInsertAsyncInternal(SqlConnection connection, string tableName, @@ -1191,7 +1211,8 @@ internal static async Task BulkInsertAsyncInternal(SqlConnection c int? batchSize = null, bool? isReturnIdentity = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Variables needed @@ -1203,7 +1224,7 @@ internal static async Task BulkInsertAsyncInternal(SqlConnection c if (transaction == null) { // Add the transaction if not present - transaction = (SqlTransaction)(await connection.EnsureOpenAsync()).BeginTransaction(); + transaction = (SqlTransaction)(await connection.EnsureOpenAsync(cancellationToken)).BeginTransaction(); } else { @@ -1214,7 +1235,7 @@ internal static async Task BulkInsertAsyncInternal(SqlConnection c try { // Get the DB Fields - dbFields = dbFields ?? await DbFieldCache.GetAsync(connection, tableName, transaction, true); + dbFields = dbFields ?? await DbFieldCache.GetAsync(connection, tableName, transaction, true, cancellationToken); // Variables needed var identityDbField = dbFields?.FirstOrDefault(dbField => dbField.IsIdentity); @@ -1285,7 +1306,7 @@ internal static async Task BulkInsertAsyncInternal(SqlConnection c tempTableName, fields, dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); } // Set the destinationtable @@ -1310,11 +1331,11 @@ internal static async Task BulkInsertAsyncInternal(SqlConnection c sqlBulkCopy.ColumnMappings.Add(mapItem.SourceColumn, mapItem.DestinationColumn)); // Open the connection and do the operation - connection.EnsureOpen(); + await connection.EnsureOpenAsync(cancellationToken); using (var reader = new DataEntityDataReader(entities)) { - await reader.InitializeAsync(); - await sqlBulkCopy.WriteToServerAsync(reader); + await reader.InitializeAsync(cancellationToken); + await sqlBulkCopy.WriteToServerAsync(reader, cancellationToken); recordsAffected = reader.RecordsAffected; } @@ -1330,13 +1351,13 @@ internal static async Task BulkInsertAsyncInternal(SqlConnection c dbSetting); // Execute the SQL - using (var reader = (DbDataReader)(await connection.ExecuteReaderAsync(sql, commandTimeout: bulkCopyTimeout, transaction: transaction))) + using (var reader = (DbDataReader)(await connection.ExecuteReaderAsync(sql, commandTimeout: bulkCopyTimeout, transaction: transaction, cancellationToken: cancellationToken))) { var func = Compiler.GetPropertySetterFunc(identityDbField.Name); var list = entities.AsList(); - while (await reader.ReadAsync()) + while (await reader.ReadAsync(cancellationToken)) { - var value = Converter.DbNullToNull(await reader.GetFieldValueAsync(0)); + var value = Converter.DbNullToNull(await reader.GetFieldValueAsync(0, cancellationToken)); var entity = list[result]; func(entity, value); result++; @@ -1345,7 +1366,7 @@ internal static async Task BulkInsertAsyncInternal(SqlConnection c // Drop the table after used sql = GetDropTemporaryTableSqlText(tempTableName, dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); } else { @@ -1398,6 +1419,7 @@ internal static async Task BulkInsertAsyncInternal(SqlConnection c /// The flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. This argument will only be used if the 'isReturnIdentity' argument is 'true'. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. internal static async Task BulkInsertAsyncInternal(SqlConnection connection, string tableName, @@ -1410,7 +1432,8 @@ internal static async Task BulkInsertAsyncInternal(SqlConnection connection int? batchSize = null, bool? isReturnIdentity = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) { // Variables needed var dbSetting = connection.GetDbSetting(); @@ -1421,7 +1444,7 @@ internal static async Task BulkInsertAsyncInternal(SqlConnection connection if (transaction == null) { // Add the transaction if not present - transaction = (SqlTransaction)(await connection.EnsureOpenAsync()).BeginTransaction(); + transaction = (SqlTransaction)(await connection.EnsureOpenAsync(cancellationToken)).BeginTransaction(); } else { @@ -1432,7 +1455,7 @@ internal static async Task BulkInsertAsyncInternal(SqlConnection connection try { // Get the DB Fields - dbFields = dbFields ?? await DbFieldCache.GetAsync(connection, tableName, transaction, true); + dbFields = dbFields ?? await DbFieldCache.GetAsync(connection, tableName, transaction, true, cancellationToken); // Variables needed var identityDbField = dbFields?.FirstOrDefault(dbField => dbField.IsIdentity); @@ -1504,7 +1527,7 @@ internal static async Task BulkInsertAsyncInternal(SqlConnection connection tempTableName, fields, dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); } // Set the destinationtable @@ -1529,8 +1552,8 @@ internal static async Task BulkInsertAsyncInternal(SqlConnection connection sqlBulkCopy.ColumnMappings.Add(mapItem.SourceColumn, mapItem.DestinationColumn)); // Open the connection and do the operation - await connection.EnsureOpenAsync(); - await sqlBulkCopy.WriteToServerAsync(reader); + await connection.EnsureOpenAsync(cancellationToken); + await sqlBulkCopy.WriteToServerAsync(reader, cancellationToken); // Check if this is with pseudo if (withPseudoExecution) @@ -1544,11 +1567,11 @@ internal static async Task BulkInsertAsyncInternal(SqlConnection connection dbSetting); // Execute the SQL - result = await connection.ExecuteNonQueryAsync(sql, commandTimeout: bulkCopyTimeout, transaction: transaction); + result = await connection.ExecuteNonQueryAsync(sql, commandTimeout: bulkCopyTimeout, transaction: transaction, cancellationToken: cancellationToken); // Drop the table after used sql = GetDropTemporaryTableSqlText(tempTableName, dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); } else { @@ -1602,6 +1625,7 @@ internal static async Task BulkInsertAsyncInternal(SqlConnection connection /// The flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. This argument will only be used if the 'isReturnIdentity' argument is 'true'. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. internal static async Task BulkInsertAsyncInternal(SqlConnection connection, string tableName, @@ -1615,7 +1639,8 @@ internal static async Task BulkInsertAsyncInternal(SqlConnection connection int? batchSize = null, bool? isReturnIdentity = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) { // Variables needed var dbSetting = connection.GetDbSetting(); @@ -1626,7 +1651,7 @@ internal static async Task BulkInsertAsyncInternal(SqlConnection connection if (transaction == null) { // Add the transaction if not present - transaction = (SqlTransaction)(await connection.EnsureOpenAsync()).BeginTransaction(); + transaction = (SqlTransaction)(await connection.EnsureOpenAsync(cancellationToken)).BeginTransaction(); } else { @@ -1637,7 +1662,7 @@ internal static async Task BulkInsertAsyncInternal(SqlConnection connection try { // Get the DB Fields - dbFields = dbFields ?? await DbFieldCache.GetAsync(connection, tableName, transaction, true); + dbFields = dbFields ?? await DbFieldCache.GetAsync(connection, tableName, transaction, true, cancellationToken); // Variables needed var identityDbField = dbFields?.FirstOrDefault(dbField => dbField.IsIdentity); @@ -1709,7 +1734,7 @@ internal static async Task BulkInsertAsyncInternal(SqlConnection connection tempTableName, fields, dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); } // Set the destinationtable @@ -1734,14 +1759,14 @@ internal static async Task BulkInsertAsyncInternal(SqlConnection connection sqlBulkCopy.ColumnMappings.Add(mapItem.SourceColumn, mapItem.DestinationColumn)); // Open the connection and do the operation - await connection.EnsureOpenAsync(); + await connection.EnsureOpenAsync(cancellationToken); if (rowState.HasValue == true) { - await sqlBulkCopy.WriteToServerAsync(dataTable, rowState.Value); + await sqlBulkCopy.WriteToServerAsync(dataTable, rowState.Value, cancellationToken); } else { - await sqlBulkCopy.WriteToServerAsync(dataTable); + await sqlBulkCopy.WriteToServerAsync(dataTable, cancellationToken); } // Check if this is with pseudo @@ -1761,11 +1786,11 @@ internal static async Task BulkInsertAsyncInternal(SqlConnection connection // Identify the column if (column?.ReadOnly == false) { - using (var reader = (DbDataReader)(await connection.ExecuteReaderAsync(sql, commandTimeout: bulkCopyTimeout, transaction: transaction))) + using (var reader = (DbDataReader)(await connection.ExecuteReaderAsync(sql, commandTimeout: bulkCopyTimeout, transaction: transaction, cancellationToken: cancellationToken))) { - while (await reader.ReadAsync()) + while (await reader.ReadAsync(cancellationToken)) { - var value = Converter.DbNullToNull(await reader.GetFieldValueAsync(0)); + var value = Converter.DbNullToNull(await reader.GetFieldValueAsync(0, cancellationToken)); dataTable.Rows[result][column] = value; result++; } @@ -1773,12 +1798,12 @@ internal static async Task BulkInsertAsyncInternal(SqlConnection connection } else { - result = await connection.ExecuteNonQueryAsync(sql, commandTimeout: bulkCopyTimeout, transaction: transaction); + result = await connection.ExecuteNonQueryAsync(sql, commandTimeout: bulkCopyTimeout, transaction: transaction, cancellationToken: cancellationToken); } // Drop the table after used sql = GetDropTemporaryTableSqlText(tempTableName, dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); } } else diff --git a/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/Microsoft.Data.SqlClient/SqlConnection/BulkMerge.cs b/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/Microsoft.Data.SqlClient/SqlConnection/BulkMerge.cs index a5a0dda38..c61bbe811 100644 --- a/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/Microsoft.Data.SqlClient/SqlConnection/BulkMerge.cs +++ b/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/Microsoft.Data.SqlClient/SqlConnection/BulkMerge.cs @@ -7,6 +7,7 @@ using System.Data.Common; using System.Linq; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -303,6 +304,7 @@ public static int BulkMerge(this SqlConnection connection, /// The flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkMergeAsync(this SqlConnection connection, IEnumerable entities, @@ -314,7 +316,8 @@ public static async Task BulkMergeAsync(this SqlConnection connect int? batchSize = null, bool? isReturnIdentity = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { return await BulkMergeAsyncInternal(connection: connection, @@ -328,7 +331,8 @@ public static async Task BulkMergeAsync(this SqlConnection connect batchSize: batchSize, isReturnIdentity: isReturnIdentity, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -347,6 +351,7 @@ public static async Task BulkMergeAsync(this SqlConnection connect /// The flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkMergeAsync(this SqlConnection connection, string tableName, @@ -359,7 +364,8 @@ public static async Task BulkMergeAsync(this SqlConnection connect int? batchSize = null, bool? isReturnIdentity = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { return await BulkMergeAsyncInternal(connection: connection, @@ -373,7 +379,8 @@ public static async Task BulkMergeAsync(this SqlConnection connect batchSize: batchSize, isReturnIdentity: isReturnIdentity, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -390,6 +397,7 @@ public static async Task BulkMergeAsync(this SqlConnection connect /// The size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkMergeAsync(this SqlConnection connection, DbDataReader reader, @@ -400,7 +408,8 @@ public static async Task BulkMergeAsync(this SqlConnection connect int? bulkCopyTimeout = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { return await BulkMergeAsyncInternal(connection: connection, @@ -414,7 +423,8 @@ public static async Task BulkMergeAsync(this SqlConnection connect batchSize: batchSize, isReturnIdentity: false, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } #endregion @@ -435,6 +445,7 @@ public static async Task BulkMergeAsync(this SqlConnection connect /// The size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkMergeAsync(this SqlConnection connection, string tableName, @@ -446,7 +457,8 @@ public static async Task BulkMergeAsync(this SqlConnection connection, int? bulkCopyTimeout = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) { return await BulkMergeAsyncInternal(connection: connection, tableName: tableName, @@ -459,7 +471,8 @@ public static async Task BulkMergeAsync(this SqlConnection connection, batchSize: batchSize, isReturnIdentity: false, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -478,6 +491,7 @@ public static async Task BulkMergeAsync(this SqlConnection connection, /// The flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkMergeAsync(this SqlConnection connection, DataTable dataTable, @@ -490,7 +504,8 @@ public static async Task BulkMergeAsync(this SqlConnection connect int? batchSize = null, bool? isReturnIdentity = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { return await BulkMergeAsyncInternal(connection: connection, @@ -505,7 +520,8 @@ public static async Task BulkMergeAsync(this SqlConnection connect batchSize: batchSize, isReturnIdentity: isReturnIdentity, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -524,6 +540,7 @@ public static async Task BulkMergeAsync(this SqlConnection connect /// The flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkMergeAsync(this SqlConnection connection, string tableName, @@ -537,7 +554,8 @@ public static async Task BulkMergeAsync(this SqlConnection connection, int? batchSize = null, bool? isReturnIdentity = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) { return await BulkMergeAsyncInternal(connection: connection, tableName: tableName, @@ -551,7 +569,8 @@ public static async Task BulkMergeAsync(this SqlConnection connection, batchSize: batchSize, isReturnIdentity: isReturnIdentity, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } #endregion @@ -573,6 +592,7 @@ public static async Task BulkMergeAsync(this SqlConnection connection, /// The flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. internal static int BulkMergeInternal(SqlConnection connection, string tableName, @@ -788,6 +808,7 @@ internal static int BulkMergeInternal(SqlConnection connection, /// The flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. internal static int BulkMergeInternal(SqlConnection connection, string tableName, @@ -984,6 +1005,7 @@ internal static int BulkMergeInternal(SqlConnection connection, /// The flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. internal static int BulkMergeInternal(SqlConnection connection, string tableName, @@ -1203,6 +1225,7 @@ internal static int BulkMergeInternal(SqlConnection connection, /// The flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. internal static async Task BulkMergeAsyncInternal(SqlConnection connection, string tableName, @@ -1215,7 +1238,8 @@ internal static async Task BulkMergeAsyncInternal(SqlConnection co int? batchSize = null, bool? isReturnIdentity = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Variables @@ -1227,7 +1251,7 @@ internal static async Task BulkMergeAsyncInternal(SqlConnection co if (transaction == null) { // Add the transaction if not present - transaction = (SqlTransaction)(await connection.EnsureOpenAsync()).BeginTransaction(); + transaction = (SqlTransaction)(await connection.EnsureOpenAsync(cancellationToken)).BeginTransaction(); } else { @@ -1250,7 +1274,7 @@ internal static async Task BulkMergeAsyncInternal(SqlConnection co try { // Get the DB Fields - var dbFields = await DbFieldCache.GetAsync(connection, tableName, transaction, true); + var dbFields = await DbFieldCache.GetAsync(connection, tableName, transaction, true, cancellationToken); // Variables needed var entityFields = FieldCache.Get().Select(f => f.Name); @@ -1299,7 +1323,7 @@ internal static async Task BulkMergeAsyncInternal(SqlConnection co tempTableName, fields, dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); // Set the options to KeepIdentity if needed if (options == null && @@ -1318,24 +1342,25 @@ internal static async Task BulkMergeAsyncInternal(SqlConnection co fields?.Any(field => string.Equals(field.Name, dbField.Name, StringComparison.OrdinalIgnoreCase)) == true); // Do the bulk insertion first - await BulkInsertAsyncInternal(connection, - tempTableName, - entities, - filteredDbFields, - mappings, - options, - null, - bulkCopyTimeout, - batchSize, - false, - false, - transaction); + await BulkInsertAsyncInternal(connection: connection, + tableName: tempTableName, + entities: entities, + dbFields: filteredDbFields, + mappings: mappings, + options: options, + hints: hints, + bulkCopyTimeout: bulkCopyTimeout, + batchSize: batchSize, + isReturnIdentity: false, + usePhysicalPseudoTempTable: false, + transaction, + cancellationToken: cancellationToken); // Create the clustered index sql = GetCreateTemporaryTableClusteredIndexSqlText(tempTableName, qualifiers, dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); // Merge the actual merge sql = GetBulkMergeSqlText(tableName, @@ -1351,17 +1376,17 @@ await BulkInsertAsyncInternal(connection, // Identity if the identity is to return if (isReturnIdentity != true) { - result = await connection.ExecuteNonQueryAsync(sql, commandTimeout: bulkCopyTimeout, transaction: transaction); + result = await connection.ExecuteNonQueryAsync(sql, commandTimeout: bulkCopyTimeout, transaction: transaction, cancellationToken: cancellationToken); } else { - using (var reader = (DbDataReader)(await connection.ExecuteReaderAsync(sql, commandTimeout: bulkCopyTimeout, transaction: transaction))) + using (var reader = (DbDataReader)(await connection.ExecuteReaderAsync(sql, commandTimeout: bulkCopyTimeout, transaction: transaction, cancellationToken: cancellationToken))) { var func = Compiler.GetPropertySetterFunc(identityDbField.Name); var list = entities.AsList(); - while (await reader.ReadAsync()) + while (await reader.ReadAsync(cancellationToken)) { - var value = Converter.DbNullToNull(await reader.GetFieldValueAsync(0)); + var value = Converter.DbNullToNull(await reader.GetFieldValueAsync(0, cancellationToken)); var entity = list[result]; func(entity, value); result++; @@ -1371,7 +1396,7 @@ await BulkInsertAsyncInternal(connection, // Drop the table after used sql = GetDropTemporaryTableSqlText(tempTableName, dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); // Commit the transaction if (hasTransaction == false) @@ -1418,6 +1443,7 @@ await BulkInsertAsyncInternal(connection, /// The flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. internal static async Task BulkMergeAsyncInternal(SqlConnection connection, string tableName, @@ -1430,7 +1456,8 @@ internal static async Task BulkMergeAsyncInternal(SqlConnection connection, int? batchSize = null, bool? isReturnIdentity = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) { // Variables var dbSetting = connection.GetDbSetting(); @@ -1441,7 +1468,7 @@ internal static async Task BulkMergeAsyncInternal(SqlConnection connection, if (transaction == null) { // Add the transaction if not present - transaction = (SqlTransaction)(await connection.EnsureOpenAsync()).BeginTransaction(); + transaction = (SqlTransaction)(await connection.EnsureOpenAsync(cancellationToken)).BeginTransaction(); } else { @@ -1464,7 +1491,7 @@ internal static async Task BulkMergeAsyncInternal(SqlConnection connection, try { // Get the DB Fields - var dbFields = await DbFieldCache.GetAsync(connection, tableName, transaction, true); + var dbFields = await DbFieldCache.GetAsync(connection, tableName, transaction, true, cancellationToken); // Variables needed var readerFields = Enumerable.Range(0, reader.FieldCount) @@ -1514,7 +1541,7 @@ internal static async Task BulkMergeAsyncInternal(SqlConnection connection, tempTableName, fields, dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); // Set the options to KeepIdentity if needed if (options == null && @@ -1533,24 +1560,25 @@ internal static async Task BulkMergeAsyncInternal(SqlConnection connection, fields?.Any(field => string.Equals(field.Name, dbField.Name, StringComparison.OrdinalIgnoreCase)) == true); // Do the bulk insertion first - await BulkInsertAsyncInternal(connection, - tempTableName, - reader, - filteredDbFields, - mappings, - options, - null, - bulkCopyTimeout, - batchSize, - false, - false, - transaction); + await BulkInsertAsyncInternal(connection: connection, + tableName: tempTableName, + reader: reader, + dbFields: filteredDbFields, + mappings: mappings, + options: options, + hints: hints, + bulkCopyTimeout: bulkCopyTimeout, + batchSize: batchSize, + isReturnIdentity: false, + usePhysicalPseudoTempTable: false, + transaction, + cancellationToken: cancellationToken); // Create the clustered index sql = GetCreateTemporaryTableClusteredIndexSqlText(tempTableName, qualifiers, dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); // Merge the actual merge sql = GetBulkMergeSqlText(tableName, @@ -1564,11 +1592,11 @@ await BulkInsertAsyncInternal(connection, isReturnIdentity.GetValueOrDefault()); // Identity if the identity is to return - result = await connection.ExecuteNonQueryAsync(sql, commandTimeout: bulkCopyTimeout, transaction: transaction); + result = await connection.ExecuteNonQueryAsync(sql, commandTimeout: bulkCopyTimeout, transaction: transaction, cancellationToken: cancellationToken); // Drop the table after used sql = GetDropTemporaryTableSqlText(tempTableName, dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); // Commit the transaction if (hasTransaction == false) @@ -1616,6 +1644,7 @@ await BulkInsertAsyncInternal(connection, /// The flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. internal static async Task BulkMergeAsyncInternal(SqlConnection connection, string tableName, @@ -1629,7 +1658,8 @@ internal static async Task BulkMergeAsyncInternal(SqlConnection connection, int? batchSize = null, bool? isReturnIdentity = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) { // Variables var dbSetting = connection.GetDbSetting(); @@ -1640,7 +1670,7 @@ internal static async Task BulkMergeAsyncInternal(SqlConnection connection, if (transaction == null) { // Add the transaction if not present - transaction = (SqlTransaction)(await connection.EnsureOpenAsync()).BeginTransaction(); + transaction = (SqlTransaction)(await connection.EnsureOpenAsync(cancellationToken)).BeginTransaction(); } else { @@ -1663,7 +1693,7 @@ internal static async Task BulkMergeAsyncInternal(SqlConnection connection, try { // Get the DB Fields - var dbFields = await DbFieldCache.GetAsync(connection, tableName, transaction, true); + var dbFields = await DbFieldCache.GetAsync(connection, tableName, transaction, true, cancellationToken); // Variables needed var tableFields = Enumerable.Range(0, dataTable.Columns.Count) @@ -1713,7 +1743,7 @@ internal static async Task BulkMergeAsyncInternal(SqlConnection connection, tempTableName, fields, dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); // Filter the DB Fields var filteredDbFields = dbFields? @@ -1721,25 +1751,26 @@ internal static async Task BulkMergeAsyncInternal(SqlConnection connection, fields?.Any(field => string.Equals(field.Name, dbField.Name, StringComparison.OrdinalIgnoreCase)) == true); // Do the bulk insertion first - await BulkInsertAsyncInternal(connection, - tempTableName, - dataTable, - rowState, - filteredDbFields, - mappings, - options, - null, - bulkCopyTimeout, - batchSize, - false, - false, - transaction); + await BulkInsertAsyncInternal(connection: connection, + tableName: tempTableName, + dataTable: dataTable, + rowState: rowState, + dbFields: filteredDbFields, + mappings: mappings, + options: options, + hints: hints, + bulkCopyTimeout: bulkCopyTimeout, + batchSize: batchSize, + isReturnIdentity: false, + usePhysicalPseudoTempTable: false, + transaction, + cancellationToken: cancellationToken); // Create the clustered index sql = GetCreateTemporaryTableClusteredIndexSqlText(tempTableName, qualifiers, dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); // Set the options to KeepIdentity if needed if (options == null && @@ -1767,11 +1798,11 @@ await BulkInsertAsyncInternal(connection, var column = dataTable.Columns[identityDbField.Name]; if (isReturnIdentity == true && column?.ReadOnly == false) { - using (var reader = (DbDataReader)(await connection.ExecuteReaderAsync(sql, commandTimeout: bulkCopyTimeout, transaction: transaction))) + using (var reader = (DbDataReader)(await connection.ExecuteReaderAsync(sql, commandTimeout: bulkCopyTimeout, transaction: transaction, cancellationToken: cancellationToken))) { - while (await reader.ReadAsync()) + while (await reader.ReadAsync(cancellationToken)) { - var value = Converter.DbNullToNull((await reader.GetFieldValueAsync(0))); + var value = Converter.DbNullToNull((await reader.GetFieldValueAsync(0, cancellationToken))); dataTable.Rows[result][column] = value; result++; } @@ -1779,12 +1810,12 @@ await BulkInsertAsyncInternal(connection, } else { - result = await connection.ExecuteNonQueryAsync(sql, commandTimeout: bulkCopyTimeout, transaction: transaction); + result = await connection.ExecuteNonQueryAsync(sql, commandTimeout: bulkCopyTimeout, transaction: transaction, cancellationToken: cancellationToken); } // Drop the table after used sql = GetDropTemporaryTableSqlText(tempTableName, dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); // Commit the transaction if (hasTransaction == false) diff --git a/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/Microsoft.Data.SqlClient/SqlConnection/BulkUpdate.cs b/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/Microsoft.Data.SqlClient/SqlConnection/BulkUpdate.cs index 6d151c9f6..2b0b1d6ff 100644 --- a/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/Microsoft.Data.SqlClient/SqlConnection/BulkUpdate.cs +++ b/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/Microsoft.Data.SqlClient/SqlConnection/BulkUpdate.cs @@ -6,6 +6,7 @@ using System.Data.Common; using System.Linq; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -295,6 +296,7 @@ public static int BulkUpdate(this SqlConnection connection, /// The size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkUpdateAsync(this SqlConnection connection, IEnumerable entities, @@ -305,12 +307,13 @@ public static async Task BulkUpdateAsync(this SqlConnection connec int? bulkCopyTimeout = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { using (var reader = new DataEntityDataReader(entities)) { - await reader.InitializeAsync(); + await reader.InitializeAsync(cancellationToken); return await BulkUpdateAsyncInternal(connection: connection, tableName: ClassMappedNameCache.Get(), reader: reader, @@ -321,7 +324,8 @@ public static async Task BulkUpdateAsync(this SqlConnection connec bulkCopyTimeout: bulkCopyTimeout, batchSize: batchSize, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } } @@ -340,6 +344,7 @@ public static async Task BulkUpdateAsync(this SqlConnection connec /// The size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkUpdateAsync(this SqlConnection connection, string tableName, @@ -351,12 +356,13 @@ public static async Task BulkUpdateAsync(this SqlConnection connec int? bulkCopyTimeout = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { using (var reader = new DataEntityDataReader(entities)) { - await reader.InitializeAsync(); + await reader.InitializeAsync(cancellationToken); return await BulkUpdateAsyncInternal(connection: connection, tableName: tableName, reader: reader, @@ -367,7 +373,8 @@ public static async Task BulkUpdateAsync(this SqlConnection connec bulkCopyTimeout: bulkCopyTimeout, batchSize: batchSize, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } } @@ -385,6 +392,7 @@ public static async Task BulkUpdateAsync(this SqlConnection connec /// The size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkUpdateAsync(this SqlConnection connection, DbDataReader reader, @@ -395,7 +403,8 @@ public static async Task BulkUpdateAsync(this SqlConnection connec int? bulkCopyTimeout = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { return await BulkUpdateAsyncInternal(connection: connection, @@ -408,7 +417,8 @@ public static async Task BulkUpdateAsync(this SqlConnection connec bulkCopyTimeout: bulkCopyTimeout, batchSize: batchSize, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } #endregion @@ -429,6 +439,7 @@ public static async Task BulkUpdateAsync(this SqlConnection connec /// The size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkUpdateAsync(this SqlConnection connection, string tableName, @@ -440,7 +451,8 @@ public static async Task BulkUpdateAsync(this SqlConnection connection, int? bulkCopyTimeout = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) { return await BulkUpdateAsyncInternal(connection: connection, tableName: tableName, @@ -452,7 +464,8 @@ public static async Task BulkUpdateAsync(this SqlConnection connection, bulkCopyTimeout: bulkCopyTimeout, batchSize: batchSize, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -470,6 +483,7 @@ public static async Task BulkUpdateAsync(this SqlConnection connection, /// The size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkUpdateAsync(this SqlConnection connection, DataTable dataTable, @@ -481,7 +495,8 @@ public static async Task BulkUpdateAsync(this SqlConnection connec int? bulkCopyTimeout = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { return await BulkUpdateAsyncInternal(connection: connection, @@ -495,7 +510,8 @@ public static async Task BulkUpdateAsync(this SqlConnection connec bulkCopyTimeout: bulkCopyTimeout, batchSize: batchSize, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -513,6 +529,7 @@ public static async Task BulkUpdateAsync(this SqlConnection connec /// The size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkUpdateAsync(this SqlConnection connection, string tableName, @@ -525,7 +542,8 @@ public static async Task BulkUpdateAsync(this SqlConnection connection, int? bulkCopyTimeout = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) { return await BulkUpdateAsyncInternal(connection: connection, tableName: tableName, @@ -538,7 +556,8 @@ public static async Task BulkUpdateAsync(this SqlConnection connection, bulkCopyTimeout: bulkCopyTimeout, batchSize: batchSize, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } #endregion @@ -559,6 +578,7 @@ public static async Task BulkUpdateAsync(this SqlConnection connection, /// The size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. internal static int BulkUpdateInternal(SqlConnection connection, string tableName, @@ -752,6 +772,7 @@ internal static int BulkUpdateInternal(SqlConnection connection, /// The size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. internal static int BulkUpdateInternal(SqlConnection connection, string tableName, @@ -947,6 +968,7 @@ internal static int BulkUpdateInternal(SqlConnection connection, /// The size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. internal static async Task BulkUpdateAsyncInternal(SqlConnection connection, string tableName, @@ -958,7 +980,8 @@ internal static async Task BulkUpdateAsyncInternal(SqlConnection connection int? bulkCopyTimeout = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) { // Variables var dbSetting = connection.GetDbSetting(); @@ -969,7 +992,7 @@ internal static async Task BulkUpdateAsyncInternal(SqlConnection connection if (transaction == null) { // Add the transaction if not present - transaction = (SqlTransaction)(await connection.EnsureOpenAsync()).BeginTransaction(); + transaction = (SqlTransaction)(await connection.EnsureOpenAsync(cancellationToken)).BeginTransaction(); } else { @@ -992,7 +1015,7 @@ internal static async Task BulkUpdateAsyncInternal(SqlConnection connection try { // Get the DB Fields - var dbFields = await DbFieldCache.GetAsync(connection, tableName, transaction, true); + var dbFields = await DbFieldCache.GetAsync(connection, tableName, transaction, true, cancellationToken); // Variables needed var readerFields = Enumerable.Range(0, reader.FieldCount) @@ -1042,7 +1065,7 @@ internal static async Task BulkUpdateAsyncInternal(SqlConnection connection tempTableName, fields, dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); // Set the options to KeepIdentity if needed if (options == null && identityDbField?.IsIdentity == true && @@ -1058,24 +1081,25 @@ internal static async Task BulkUpdateAsyncInternal(SqlConnection connection fields?.Any(field => string.Equals(field.Name, dbField.Name, StringComparison.OrdinalIgnoreCase)) == true); // Do the bulk insertion first - await BulkInsertAsyncInternal(connection, - tempTableName, - reader, - filteredDbFields, - mappings, - options, - null, - bulkCopyTimeout, - batchSize, - false, - false, - transaction); + await BulkInsertAsyncInternal(connection: connection, + tableName: tempTableName, + reader: reader, + dbFields: filteredDbFields, + mappings: mappings, + options: options, + hints: hints, + bulkCopyTimeout: bulkCopyTimeout, + batchSize: batchSize, + isReturnIdentity: false, + usePhysicalPseudoTempTable: false, + transaction: transaction, + cancellationToken: cancellationToken); // Create the clustered index sql = GetCreateTemporaryTableClusteredIndexSqlText(tempTableName, qualifiers, dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); // Update the actual update sql = GetBulkUpdateSqlText(tableName, @@ -1086,11 +1110,11 @@ await BulkInsertAsyncInternal(connection, identityDbField?.AsField(), hints, dbSetting); - result = await connection.ExecuteNonQueryAsync(sql, commandTimeout: bulkCopyTimeout, transaction: transaction); + result = await connection.ExecuteNonQueryAsync(sql, commandTimeout: bulkCopyTimeout, transaction: transaction, cancellationToken: cancellationToken); // Drop the table after used sql = GetDropTemporaryTableSqlText(tempTableName, dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); // Commit the transaction if (hasTransaction == false) @@ -1137,6 +1161,7 @@ await BulkInsertAsyncInternal(connection, /// The size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. internal static async Task BulkUpdateAsyncInternal(SqlConnection connection, string tableName, @@ -1149,7 +1174,8 @@ internal static async Task BulkUpdateAsyncInternal(SqlConnection connection int? bulkCopyTimeout = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) { // Variables var dbSetting = connection.GetDbSetting(); @@ -1160,7 +1186,7 @@ internal static async Task BulkUpdateAsyncInternal(SqlConnection connection if (transaction == null) { // Add the transaction if not present - transaction = (SqlTransaction)(await connection.EnsureOpenAsync()).BeginTransaction(); + transaction = (SqlTransaction)(await connection.EnsureOpenAsync(cancellationToken)).BeginTransaction(); } else { @@ -1183,7 +1209,7 @@ internal static async Task BulkUpdateAsyncInternal(SqlConnection connection try { // Get the DB Fields - var dbFields = await DbFieldCache.GetAsync(connection, tableName, transaction, true); + var dbFields = await DbFieldCache.GetAsync(connection, tableName, transaction, true, cancellationToken: cancellationToken); // Variables needed var tableFields = Enumerable.Range(0, dataTable.Columns.Count) @@ -1233,7 +1259,7 @@ internal static async Task BulkUpdateAsyncInternal(SqlConnection connection tempTableName, fields, dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); // Set the options to KeepIdentity if needed if (options == null && identityDbField?.IsIdentity == true && @@ -1249,25 +1275,26 @@ internal static async Task BulkUpdateAsyncInternal(SqlConnection connection fields?.Any(field => string.Equals(field.Name, dbField.Name, StringComparison.OrdinalIgnoreCase)) == true); // Do the bulk insertion first - await BulkInsertAsyncInternal(connection, - tempTableName, - dataTable, - rowState, - filteredDbFields, - mappings, - options, - null, - bulkCopyTimeout, - batchSize, - false, - false, - transaction); + await BulkInsertAsyncInternal(connection: connection, + tableName: tempTableName, + dataTable: dataTable, + rowState: rowState, + dbFields: filteredDbFields, + mappings: mappings, + options: options, + hints: hints, + bulkCopyTimeout: bulkCopyTimeout, + batchSize: batchSize, + isReturnIdentity: false, + usePhysicalPseudoTempTable: false, + transaction: transaction, + cancellationToken: cancellationToken); // Create the clustered index sql = GetCreateTemporaryTableClusteredIndexSqlText(tempTableName, qualifiers, dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); // Update the actual update sql = GetBulkUpdateSqlText(tableName, @@ -1278,11 +1305,11 @@ await BulkInsertAsyncInternal(connection, identityDbField?.AsField(), hints, dbSetting); - result = await connection.ExecuteNonQueryAsync(sql, commandTimeout: bulkCopyTimeout, transaction: transaction); + result = await connection.ExecuteNonQueryAsync(sql, commandTimeout: bulkCopyTimeout, transaction: transaction, cancellationToken: cancellationToken); // Drop the table after used sql = GetDropTemporaryTableSqlText(tempTableName, dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); // Commit the transaction if (hasTransaction == false) diff --git a/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/System.Data.SqlClient/BaseRepository/BulkDelete.cs b/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/System.Data.SqlClient/BaseRepository/BulkDelete.cs index 1e00be0da..c53c869e1 100644 --- a/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/System.Data.SqlClient/BaseRepository/BulkDelete.cs +++ b/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/System.Data.SqlClient/BaseRepository/BulkDelete.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Data.SqlClient; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -126,20 +127,23 @@ public static int BulkDelete(this BaseRepositoryThe size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static Task BulkDeleteAsync(this BaseRepository repository, IEnumerable primaryKeys, string hints = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { return repository.DbRepository.BulkDeleteAsync(primaryKeys: primaryKeys, hints: hints, batchSize: batchSize, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -155,6 +159,7 @@ public static Task BulkDeleteAsync(this BaseRepositoryThe size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static Task BulkDeleteAsync(this BaseRepository repository, IEnumerable entities, @@ -164,7 +169,8 @@ public static Task BulkDeleteAsync(this BaseRepository(entities: entities, @@ -174,7 +180,8 @@ public static Task BulkDeleteAsync(this BaseRepository @@ -191,6 +198,7 @@ public static Task BulkDeleteAsync(this BaseRepositoryThe size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static Task BulkDeleteAsync(this BaseRepository repository, string tableName, @@ -201,7 +209,8 @@ public static Task BulkDeleteAsync(this BaseRepository(tableName: tableName, @@ -212,7 +221,8 @@ public static Task BulkDeleteAsync(this BaseRepository(this BaseRepositoryThe flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. This argument will only be used if the 'isReturnIdentity' argument is 'true'. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static Task BulkInsertAsync(this BaseRepository repository, IEnumerable entities, @@ -110,7 +112,8 @@ public static Task BulkInsertAsync(this BaseRepository(entities: entities, @@ -120,7 +123,8 @@ public static Task BulkInsertAsync(this BaseRepository @@ -137,6 +141,7 @@ public static Task BulkInsertAsync(this BaseRepositoryThe flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. This argument will only be used if the 'isReturnIdentity' argument is 'true'. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static Task BulkInsertAsync(this BaseRepository repository, string tableName, @@ -147,7 +152,8 @@ public static Task BulkInsertAsync(this BaseRepository(tableName: tableName, @@ -158,7 +164,8 @@ public static Task BulkInsertAsync(this BaseRepositoryThe flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static int BulkMerge(this BaseRepository repository, IEnumerable entities, @@ -66,6 +68,7 @@ public static int BulkMerge(this BaseRepository /// The flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static int BulkMerge(this BaseRepository repository, string tableName, @@ -110,6 +113,7 @@ public static int BulkMerge(this BaseRepository /// The flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static Task BulkMergeAsync(this BaseRepository repository, IEnumerable entities, @@ -120,7 +124,8 @@ public static Task BulkMergeAsync(this BaseRepository(entities: entities, @@ -131,7 +136,8 @@ public static Task BulkMergeAsync(this BaseRepository @@ -149,6 +155,7 @@ public static Task BulkMergeAsync(this BaseRepositoryThe flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static Task BulkMergeAsync(this BaseRepository repository, string tableName, @@ -160,7 +167,8 @@ public static Task BulkMergeAsync(this BaseRepository(tableName: tableName, @@ -172,7 +180,8 @@ public static Task BulkMergeAsync(this BaseRepository(this BaseRepositoryThe size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static Task BulkUpdateAsync(this BaseRepository repository, IEnumerable entities, @@ -112,7 +114,8 @@ public static Task BulkUpdateAsync(this BaseRepository(entities: entities, @@ -122,7 +125,8 @@ public static Task BulkUpdateAsync(this BaseRepository @@ -139,6 +143,7 @@ public static Task BulkUpdateAsync(this BaseRepositoryThe size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static Task BulkUpdateAsync(this BaseRepository repository, string tableName, @@ -149,7 +154,8 @@ public static Task BulkUpdateAsync(this BaseRepository(tableName: tableName, @@ -160,7 +166,8 @@ public static Task BulkUpdateAsync(this BaseRepository repository, /// The size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkDeleteAsync(this DbRepository repository, IEnumerable primaryKeys, string hints = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -520,7 +523,8 @@ public static async Task BulkDeleteAsync(this DbRepository BulkDeleteAsync(this DbRepositoryThe size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkDeleteAsync(this DbRepository repository, IEnumerable entities, @@ -562,7 +567,8 @@ public static async Task BulkDeleteAsync(this DbRepository BulkDeleteAsync(this DbRepository BulkDeleteAsync(this DbRepositoryThe size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkDeleteAsync(this DbRepository repository, string tableName, @@ -623,7 +631,8 @@ public static async Task BulkDeleteAsync(this DbRepository BulkDeleteAsync(this DbRepository BulkDeleteAsync(this DbRepositoryThe size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkDeleteAsync(this DbRepository repository, DbDataReader reader, @@ -683,7 +694,8 @@ public static async Task BulkDeleteAsync(this DbRepository BulkDeleteAsync(this DbRepository BulkDeleteAsync(this DbRepositoryThe size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkDeleteAsync(this DbRepository repository, DataTable dataTable, @@ -744,7 +758,8 @@ public static async Task BulkDeleteAsync(this DbRepository BulkDeleteAsync(this DbRepository BulkDeleteAsync(this DbRepositoryThe size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkDeleteAsync(this DbRepository repository, string tableName, @@ -803,7 +820,8 @@ public static async Task BulkDeleteAsync(this DbRepository r string hints = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? repository.CreateConnection()); @@ -817,7 +835,8 @@ public static async Task BulkDeleteAsync(this DbRepository r bulkCopyTimeout: repository.CommandTimeout, batchSize: batchSize, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } catch { @@ -850,6 +869,7 @@ public static async Task BulkDeleteAsync(this DbRepository r /// The size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkDeleteAsync(this DbRepository repository, string tableName, @@ -860,7 +880,8 @@ public static async Task BulkDeleteAsync(this DbRepository r string hints = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? repository.CreateConnection()); @@ -877,7 +898,8 @@ public static async Task BulkDeleteAsync(this DbRepository r bulkCopyTimeout: repository.CommandTimeout, batchSize: batchSize, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } catch { @@ -911,6 +933,7 @@ public static async Task BulkDeleteAsync(this DbRepository r /// The size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkDeleteAsync(this DbRepository repository, string tableName, @@ -922,7 +945,8 @@ public static async Task BulkDeleteAsync(this DbRepository r string hints = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? repository.CreateConnection()); @@ -940,7 +964,8 @@ public static async Task BulkDeleteAsync(this DbRepository r bulkCopyTimeout: repository.CommandTimeout, batchSize: batchSize, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } catch { diff --git a/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/System.Data.SqlClient/DbRepository/BulkInsert.cs b/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/System.Data.SqlClient/DbRepository/BulkInsert.cs index 51b657b30..44b52b585 100644 --- a/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/System.Data.SqlClient/DbRepository/BulkInsert.cs +++ b/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/System.Data.SqlClient/DbRepository/BulkInsert.cs @@ -3,6 +3,7 @@ using System.Data; using System.Data.Common; using System.Data.SqlClient; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -382,6 +383,7 @@ public static int BulkInsert(this DbRepository repository, /// The flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. This argument will only be used if the 'isReturnIdentity' argument is 'true'. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkInsertAsync(this DbRepository repository, IEnumerable entities, @@ -391,7 +393,8 @@ public static async Task BulkInsertAsync(this DbRepository BulkInsertAsync(this DbRepository BulkInsertAsync(this DbRepositoryThe flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. This argument will only be used if the 'isReturnIdentity' argument is 'true'. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkInsertAsync(this DbRepository repository, string tableName, @@ -452,7 +457,8 @@ public static async Task BulkInsertAsync(this DbRepository BulkInsertAsync(this DbRepository BulkInsertAsync(this DbRepositoryThe bulk-copy options to be used. /// The size per batch to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkInsertAsync(this DbRepository repository, DbDataReader reader, IEnumerable mappings = null, SqlBulkCopyOptions? options = null, int? batchSize = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Create a connection @@ -520,7 +529,8 @@ public static async Task BulkInsertAsync(this DbRepository BulkInsertAsync(this DbRepositoryThe bulk-copy options to be used. /// The size per batch to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkInsertAsync(this DbRepository repository, string tableName, @@ -561,7 +572,8 @@ public static async Task BulkInsertAsync(this DbRepository r IEnumerable mappings = null, SqlBulkCopyOptions? options = null, int? batchSize = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? repository.CreateConnection()); @@ -575,7 +587,8 @@ public static async Task BulkInsertAsync(this DbRepository r options: options, bulkCopyTimeout: repository.CommandTimeout, batchSize: batchSize, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } catch { @@ -609,6 +622,7 @@ public static async Task BulkInsertAsync(this DbRepository r /// The flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. This argument will only be used if the 'isReturnIdentity' argument is 'true'. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkInsertAsync(this DbRepository repository, DataTable dataTable, @@ -619,7 +633,8 @@ public static async Task BulkInsertAsync(this DbRepository BulkInsertAsync(this DbRepository BulkInsertAsync(this DbRepositoryThe flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. This argument will only be used if the 'isReturnIdentity' argument is 'true'. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkInsertAsync(this DbRepository repository, string tableName, @@ -682,7 +699,8 @@ public static async Task BulkInsertAsync(this DbRepository r int? batchSize = null, bool? isReturnIdentity = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? repository.CreateConnection()); @@ -700,7 +718,8 @@ public static async Task BulkInsertAsync(this DbRepository r batchSize: batchSize, isReturnIdentity: isReturnIdentity, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } catch { diff --git a/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/System.Data.SqlClient/DbRepository/BulkMerge.cs b/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/System.Data.SqlClient/DbRepository/BulkMerge.cs index cddb0fb0f..c26dd505f 100644 --- a/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/System.Data.SqlClient/DbRepository/BulkMerge.cs +++ b/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/System.Data.SqlClient/DbRepository/BulkMerge.cs @@ -5,6 +5,7 @@ using System.Data.Common; using System.Data.SqlClient; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -415,6 +416,7 @@ public static int BulkMerge(this DbRepository repository, /// The flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkMergeAsync(this DbRepository repository, IEnumerable entities, @@ -425,7 +427,8 @@ public static async Task BulkMergeAsync(this DbRepository BulkMergeAsync(this DbRepository BulkMergeAsync(this DbRepositoryThe flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkMergeAsync(this DbRepository repository, string tableName, @@ -489,7 +494,8 @@ public static async Task BulkMergeAsync(this DbRepository BulkMergeAsync(this DbRepository BulkMergeAsync(this DbRepositoryThe size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkMergeAsync(this DbRepository repository, DbDataReader reader, @@ -550,7 +558,8 @@ public static async Task BulkMergeAsync(this DbRepository BulkMergeAsync(this DbRepository BulkMergeAsync(this DbRepositoryThe size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkMergeAsync(this DbRepository repository, string tableName, @@ -614,7 +625,8 @@ public static async Task BulkMergeAsync(this DbRepository re string hints = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? repository.CreateConnection()); @@ -631,7 +643,8 @@ public static async Task BulkMergeAsync(this DbRepository re bulkCopyTimeout: repository.CommandTimeout, batchSize: batchSize, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } catch { @@ -666,6 +679,7 @@ public static async Task BulkMergeAsync(this DbRepository re /// The flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkMergeAsync(this DbRepository repository, DataTable dataTable, @@ -677,7 +691,8 @@ public static async Task BulkMergeAsync(this DbRepository BulkMergeAsync(this DbRepository BulkMergeAsync(this DbRepositoryThe flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkMergeAsync(this DbRepository repository, string tableName, @@ -743,7 +760,8 @@ public static async Task BulkMergeAsync(this DbRepository re int? batchSize = null, bool? isReturnIdentity = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? repository.CreateConnection()); @@ -762,7 +780,8 @@ public static async Task BulkMergeAsync(this DbRepository re batchSize: batchSize, isReturnIdentity: isReturnIdentity, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } catch { diff --git a/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/System.Data.SqlClient/DbRepository/BulkUpdate.cs b/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/System.Data.SqlClient/DbRepository/BulkUpdate.cs index 625206735..e491e20b3 100644 --- a/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/System.Data.SqlClient/DbRepository/BulkUpdate.cs +++ b/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/System.Data.SqlClient/DbRepository/BulkUpdate.cs @@ -5,6 +5,7 @@ using System.Data.Common; using System.Data.SqlClient; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -402,6 +403,7 @@ public static int BulkUpdate(this DbRepository repository, /// The size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkUpdateAsync(this DbRepository repository, IEnumerable entities, @@ -411,7 +413,8 @@ public static async Task BulkUpdateAsync(this DbRepository BulkUpdateAsync(this DbRepository BulkUpdateAsync(this DbRepositoryThe size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkUpdateAsync(this DbRepository repository, string tableName, @@ -472,7 +477,8 @@ public static async Task BulkUpdateAsync(this DbRepository BulkUpdateAsync(this DbRepository BulkUpdateAsync(this DbRepositoryThe size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkUpdateAsync(this DbRepository repository, DbDataReader reader, @@ -532,7 +540,8 @@ public static async Task BulkUpdateAsync(this DbRepository BulkUpdateAsync(this DbRepository BulkUpdateAsync(this DbRepositoryThe size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkUpdateAsync(this DbRepository repository, string tableName, @@ -596,7 +607,8 @@ public static async Task BulkUpdateAsync(this DbRepository r string hints = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? repository.CreateConnection()); @@ -613,7 +625,8 @@ public static async Task BulkUpdateAsync(this DbRepository r bulkCopyTimeout: repository.CommandTimeout, batchSize: batchSize, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } catch { @@ -647,6 +660,7 @@ public static async Task BulkUpdateAsync(this DbRepository r /// The size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkUpdateAsync(this DbRepository repository, DataTable dataTable, @@ -657,7 +671,8 @@ public static async Task BulkUpdateAsync(this DbRepository BulkUpdateAsync(this DbRepository BulkUpdateAsync(this DbRepositoryThe size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkUpdateAsync(this DbRepository repository, string tableName, @@ -720,7 +737,8 @@ public static async Task BulkUpdateAsync(this DbRepository r string hints = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) { // Create a connection var connection = (transaction?.Connection ?? repository.CreateConnection()); @@ -738,7 +756,8 @@ public static async Task BulkUpdateAsync(this DbRepository r bulkCopyTimeout: repository.CommandTimeout, batchSize: batchSize, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } catch { diff --git a/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/System.Data.SqlClient/SqlConnection/BulkDelete.cs b/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/System.Data.SqlClient/SqlConnection/BulkDelete.cs index 434ef56da..ca4cec3cb 100644 --- a/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/System.Data.SqlClient/SqlConnection/BulkDelete.cs +++ b/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/System.Data.SqlClient/SqlConnection/BulkDelete.cs @@ -6,6 +6,7 @@ using System.Data.SqlClient; using System.Linq; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -354,6 +355,7 @@ public static int BulkDelete(this SqlConnection connection, /// The size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkDeleteAsync(this SqlConnection connection, IEnumerable primaryKeys, @@ -361,7 +363,8 @@ public static async Task BulkDeleteAsync(this SqlConnection connec int? bulkCopyTimeout = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { return await BulkDeleteAsyncInternal(connection: connection, @@ -371,7 +374,8 @@ public static async Task BulkDeleteAsync(this SqlConnection connec bulkCopyTimeout: bulkCopyTimeout, batchSize: batchSize, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -388,6 +392,7 @@ public static async Task BulkDeleteAsync(this SqlConnection connec /// The size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkDeleteAsync(this SqlConnection connection, IEnumerable entities, @@ -398,12 +403,13 @@ public static async Task BulkDeleteAsync(this SqlConnection connec int? bulkCopyTimeout = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { using (var reader = new DataEntityDataReader(entities)) { - await reader.InitializeAsync(); + await reader.InitializeAsync(cancellationToken); return await BulkDeleteAsyncInternal(connection: connection, tableName: ClassMappedNameCache.Get(), reader: reader, @@ -414,7 +420,8 @@ public static async Task BulkDeleteAsync(this SqlConnection connec bulkCopyTimeout: bulkCopyTimeout, batchSize: batchSize, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } } @@ -433,6 +440,7 @@ public static async Task BulkDeleteAsync(this SqlConnection connec /// The size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkDeleteAsync(this SqlConnection connection, string tableName, @@ -444,12 +452,13 @@ public static async Task BulkDeleteAsync(this SqlConnection connec int? bulkCopyTimeout = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { using (var reader = new DataEntityDataReader(entities)) { - await reader.InitializeAsync(); + await reader.InitializeAsync(cancellationToken); return await BulkDeleteAsyncInternal(connection: connection, tableName: tableName, reader: reader, @@ -460,7 +469,8 @@ public static async Task BulkDeleteAsync(this SqlConnection connec bulkCopyTimeout: bulkCopyTimeout, batchSize: batchSize, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } } @@ -478,6 +488,7 @@ public static async Task BulkDeleteAsync(this SqlConnection connec /// The size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkDeleteAsync(this SqlConnection connection, DbDataReader reader, @@ -488,7 +499,8 @@ public static async Task BulkDeleteAsync(this SqlConnection connec int? bulkCopyTimeout = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { return await BulkDeleteAsyncInternal(connection: connection, @@ -501,7 +513,8 @@ public static async Task BulkDeleteAsync(this SqlConnection connec bulkCopyTimeout: bulkCopyTimeout, batchSize: batchSize, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -519,6 +532,7 @@ public static async Task BulkDeleteAsync(this SqlConnection connec /// The size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkDeleteAsync(this SqlConnection connection, DataTable dataTable, @@ -530,7 +544,8 @@ public static async Task BulkDeleteAsync(this SqlConnection connec int? bulkCopyTimeout = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { return await BulkDeleteAsyncInternal(connection: connection, @@ -544,7 +559,8 @@ public static async Task BulkDeleteAsync(this SqlConnection connec bulkCopyTimeout: bulkCopyTimeout, batchSize: batchSize, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } #endregion @@ -562,6 +578,7 @@ public static async Task BulkDeleteAsync(this SqlConnection connec /// The size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkDeleteAsync(this SqlConnection connection, string tableName, @@ -570,7 +587,8 @@ public static async Task BulkDeleteAsync(this SqlConnection connection, int? bulkCopyTimeout = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) { return await BulkDeleteAsyncInternal(connection: connection, tableName: tableName, @@ -579,7 +597,8 @@ public static async Task BulkDeleteAsync(this SqlConnection connection, bulkCopyTimeout: bulkCopyTimeout, batchSize: batchSize, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -596,6 +615,7 @@ public static async Task BulkDeleteAsync(this SqlConnection connection, /// The size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkDeleteAsync(this SqlConnection connection, string tableName, @@ -607,7 +627,8 @@ public static async Task BulkDeleteAsync(this SqlConnection connection, int? bulkCopyTimeout = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) { return await BulkDeleteAsyncInternal(connection: connection, tableName: tableName, @@ -619,7 +640,8 @@ public static async Task BulkDeleteAsync(this SqlConnection connection, bulkCopyTimeout: bulkCopyTimeout, batchSize: batchSize, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -637,6 +659,7 @@ public static async Task BulkDeleteAsync(this SqlConnection connection, /// The size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkDeleteAsync(this SqlConnection connection, string tableName, @@ -649,7 +672,8 @@ public static async Task BulkDeleteAsync(this SqlConnection connection, int? bulkCopyTimeout = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) { return await BulkDeleteAsyncInternal(connection: connection, tableName: tableName, @@ -662,7 +686,8 @@ public static async Task BulkDeleteAsync(this SqlConnection connection, bulkCopyTimeout: bulkCopyTimeout, batchSize: batchSize, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } #endregion @@ -1212,6 +1237,7 @@ internal static int BulkDeleteInternal(SqlConnection connection, /// The size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. internal static async Task BulkDeleteAsyncInternal(SqlConnection connection, string tableName, @@ -1220,7 +1246,8 @@ internal static async Task BulkDeleteAsyncInternal(SqlConnection connection int? bulkCopyTimeout = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) { // Variables var dbSetting = connection.GetDbSetting(); @@ -1231,7 +1258,7 @@ internal static async Task BulkDeleteAsyncInternal(SqlConnection connection if (transaction == null) { // Add the transaction if not present - transaction = (SqlTransaction)(await connection.EnsureOpenAsync()).BeginTransaction(); + transaction = (SqlTransaction)(await connection.EnsureOpenAsync(cancellationToken)).BeginTransaction(); } else { @@ -1254,7 +1281,7 @@ internal static async Task BulkDeleteAsyncInternal(SqlConnection connection try { // Get the DB Fields - var dbFields = await DbFieldCache.GetAsync(connection, tableName, transaction, true); + var dbFields = await DbFieldCache.GetAsync(connection, tableName, transaction, true, cancellationToken); // Variables needed var primaryDbField = dbFields?.FirstOrDefault(dbField => dbField.IsPrimary); @@ -1273,7 +1300,7 @@ internal static async Task BulkDeleteAsyncInternal(SqlConnection connection tempTableName, primaryOrIdentityField.AsEnumerable(), dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); // Do the bulk insertion first using (var dataTable = CreateDataTableWithSingleColumn(primaryOrIdentityField, primaryKeys)) @@ -1289,14 +1316,15 @@ await BulkInsertAsyncInternal(connection, options: options, bulkCopyTimeout: bulkCopyTimeout, batchSize: batchSize, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } // Create the clustered index sql = GetCreateTemporaryTableClusteredIndexSqlText(tempTableName, primaryOrIdentityField.AsEnumerable(), dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); // Delete the actual delete sql = GetBulkDeleteSqlText(tableName, @@ -1304,11 +1332,11 @@ await BulkInsertAsyncInternal(connection, primaryOrIdentityField.AsEnumerable(), hints, dbSetting); - result = connection.ExecuteNonQuery(sql, commandTimeout: bulkCopyTimeout, transaction: transaction); + result = await connection.ExecuteNonQueryAsync(sql, commandTimeout: bulkCopyTimeout, transaction: transaction, cancellationToken: cancellationToken); // Drop the table after used sql = GetDropTemporaryTableSqlText(tempTableName, dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); // Commit the transaction if (hasTransaction == false) @@ -1354,6 +1382,7 @@ await BulkInsertAsyncInternal(connection, /// The size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. internal static async Task BulkDeleteAsyncInternal(SqlConnection connection, string tableName, @@ -1365,7 +1394,8 @@ internal static async Task BulkDeleteAsyncInternal(SqlConnection connection int? bulkCopyTimeout = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) { // Variables var dbSetting = connection.GetDbSetting(); @@ -1376,7 +1406,7 @@ internal static async Task BulkDeleteAsyncInternal(SqlConnection connection if (transaction == null) { // Add the transaction if not present - transaction = (SqlTransaction)(await connection.EnsureOpenAsync()).BeginTransaction(); + transaction = (SqlTransaction)(await connection.EnsureOpenAsync(cancellationToken)).BeginTransaction(); } else { @@ -1399,7 +1429,7 @@ internal static async Task BulkDeleteAsyncInternal(SqlConnection connection try { // Get the DB Fields - var dbFields = await DbFieldCache.GetAsync(connection, tableName, transaction, true); + var dbFields = await DbFieldCache.GetAsync(connection, tableName, transaction, true, cancellationToken); // Variables needed var readerFields = Enumerable.Range(0, reader.FieldCount) @@ -1449,7 +1479,7 @@ internal static async Task BulkDeleteAsyncInternal(SqlConnection connection tempTableName, fields, dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); // Set the options to KeepIdentity if needed if (options == null && identityDbField?.IsIdentity == true && @@ -1471,24 +1501,25 @@ internal static async Task BulkDeleteAsyncInternal(SqlConnection connection fields?.Any(field => string.Equals(field.Name, dbField.Name, StringComparison.OrdinalIgnoreCase)) == true); // Do the bulk insertion first - await BulkInsertAsyncInternal(connection, - tempTableName, - reader, - filteredDbFields, - mappings, - options, - null, + await BulkInsertAsyncInternal(connection: connection, + tableName: tempTableName, + reader: reader, + dbFields: filteredDbFields, + mappings: mappings, + options: options, + hints: hints, bulkCopyTimeout, batchSize, - false, - false, - transaction); + isReturnIdentity: false, + usePhysicalPseudoTempTable: false, + transaction: transaction, + cancellationToken: cancellationToken); // Create the clustered index sql = GetCreateTemporaryTableClusteredIndexSqlText(tempTableName, qualifiers, dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); // Delete the actual delete sql = GetBulkDeleteSqlText(tableName, @@ -1496,11 +1527,11 @@ await BulkInsertAsyncInternal(connection, qualifiers, hints, dbSetting); - result = await connection.ExecuteNonQueryAsync(sql, commandTimeout: bulkCopyTimeout, transaction: transaction); + result = await connection.ExecuteNonQueryAsync(sql, commandTimeout: bulkCopyTimeout, transaction: transaction, cancellationToken: cancellationToken); // Drop the table after used sql = GetDropTemporaryTableSqlText(tempTableName, dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); // Commit the transaction if (hasTransaction == false) @@ -1547,6 +1578,7 @@ await BulkInsertAsyncInternal(connection, /// The size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. internal static async Task BulkDeleteAsyncInternal(SqlConnection connection, string tableName, @@ -1559,7 +1591,8 @@ internal static async Task BulkDeleteAsyncInternal(SqlConnection connection int? bulkCopyTimeout = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) { // Variables var dbSetting = connection.GetDbSetting(); @@ -1570,7 +1603,7 @@ internal static async Task BulkDeleteAsyncInternal(SqlConnection connection if (transaction == null) { // Add the transaction if not present - transaction = (SqlTransaction)(await connection.EnsureOpenAsync()).BeginTransaction(); + transaction = (SqlTransaction)(await connection.EnsureOpenAsync(cancellationToken)).BeginTransaction(); } else { @@ -1593,7 +1626,7 @@ internal static async Task BulkDeleteAsyncInternal(SqlConnection connection try { // Get the DB Fields - var dbFields = await DbFieldCache.GetAsync(connection, tableName, transaction, true); + var dbFields = await DbFieldCache.GetAsync(connection, tableName, transaction, true, cancellationToken); // Variables needed var tableFields = Enumerable.Range(0, dataTable.Columns.Count) @@ -1643,7 +1676,7 @@ internal static async Task BulkDeleteAsyncInternal(SqlConnection connection tempTableName, fields, dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); // Set the options to KeepIdentity if needed if (options == null && identityDbField?.IsIdentity == true && @@ -1665,25 +1698,26 @@ internal static async Task BulkDeleteAsyncInternal(SqlConnection connection fields?.Any(field => string.Equals(field.Name, dbField.Name, StringComparison.OrdinalIgnoreCase)) == true); // Do the bulk insertion first - await BulkInsertAsyncInternal(connection, - tempTableName, - dataTable, - rowState, - filteredDbFields, - mappings, - options, - null, + await BulkInsertAsyncInternal(connection: connection, + tableName: tempTableName, + dataTable: dataTable, + rowState: rowState, + dbFields: filteredDbFields, + mappings: mappings, + options: options, + hints: hints, bulkCopyTimeout, batchSize, - false, - false, - transaction); + isReturnIdentity: false, + usePhysicalPseudoTempTable: false, + transaction: transaction, + cancellationToken: cancellationToken); // Create the clustered index sql = GetCreateTemporaryTableClusteredIndexSqlText(tempTableName, qualifiers, dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); // Delete the actual delete sql = GetBulkDeleteSqlText(tableName, @@ -1691,11 +1725,11 @@ await BulkInsertAsyncInternal(connection, qualifiers, hints, dbSetting); - result = await connection.ExecuteNonQueryAsync(sql, commandTimeout: bulkCopyTimeout, transaction: transaction); + result = await connection.ExecuteNonQueryAsync(sql, commandTimeout: bulkCopyTimeout, transaction: transaction, cancellationToken: cancellationToken); // Drop the table after used sql = GetDropTemporaryTableSqlText(tempTableName, dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); // Commit the transaction if (hasTransaction == false) diff --git a/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/System.Data.SqlClient/SqlConnection/BulkInsert.cs b/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/System.Data.SqlClient/SqlConnection/BulkInsert.cs index b31cbda8b..766644875 100644 --- a/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/System.Data.SqlClient/SqlConnection/BulkInsert.cs +++ b/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/System.Data.SqlClient/SqlConnection/BulkInsert.cs @@ -7,6 +7,7 @@ using System.Data.Common; using System.Data.SqlClient; using System.Linq; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -276,6 +277,7 @@ public static int BulkInsert(this SqlConnection connection, /// The flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. This argument will only be used if the 'isReturnIdentity' argument is 'true'. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkInsertAsync(this SqlConnection connection, IEnumerable entities, @@ -286,7 +288,8 @@ public static async Task BulkInsertAsync(this SqlConnection connec int? batchSize = null, bool? isReturnIdentity = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { return await BulkInsertAsyncInternal(connection: connection, @@ -300,7 +303,8 @@ public static async Task BulkInsertAsync(this SqlConnection connec batchSize: batchSize, isReturnIdentity: isReturnIdentity, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -318,6 +322,7 @@ public static async Task BulkInsertAsync(this SqlConnection connec /// The flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. This argument will only be used if the 'isReturnIdentity' argument is 'true'. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkInsertAsync(this SqlConnection connection, string tableName, @@ -329,7 +334,8 @@ public static async Task BulkInsertAsync(this SqlConnection connec int? batchSize = null, bool? isReturnIdentity = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { return await BulkInsertAsyncInternal(connection: connection, @@ -343,7 +349,8 @@ public static async Task BulkInsertAsync(this SqlConnection connec batchSize: batchSize, isReturnIdentity: isReturnIdentity, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -357,6 +364,7 @@ public static async Task BulkInsertAsync(this SqlConnection connec /// The timeout in seconds to be used. /// The size per batch to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkInsertAsync(this SqlConnection connection, DbDataReader reader, @@ -364,7 +372,8 @@ public static async Task BulkInsertAsync(this SqlConnection connec SqlBulkCopyOptions? options = null, int? bulkCopyTimeout = null, int? batchSize = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { return await BulkInsertAsyncInternal(connection: connection, @@ -375,7 +384,8 @@ public static async Task BulkInsertAsync(this SqlConnection connec options: options, bulkCopyTimeout: bulkCopyTimeout, batchSize: batchSize, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } #endregion @@ -393,6 +403,7 @@ public static async Task BulkInsertAsync(this SqlConnection connec /// The timeout in seconds to be used. /// The size per batch to be used. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkInsertAsync(this SqlConnection connection, string tableName, @@ -401,7 +412,8 @@ public static async Task BulkInsertAsync(this SqlConnection connection, SqlBulkCopyOptions? options = null, int? bulkCopyTimeout = null, int? batchSize = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) { return await BulkInsertAsyncInternal(connection: connection, tableName: tableName, @@ -411,7 +423,8 @@ public static async Task BulkInsertAsync(this SqlConnection connection, options: options, bulkCopyTimeout: bulkCopyTimeout, batchSize: batchSize, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -429,6 +442,7 @@ public static async Task BulkInsertAsync(this SqlConnection connection, /// The flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. This argument will only be used if the 'isReturnIdentity' argument is 'true'. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkInsertAsync(this SqlConnection connection, DataTable dataTable, @@ -440,7 +454,8 @@ public static async Task BulkInsertAsync(this SqlConnection connec int? batchSize = null, bool? isReturnIdentity = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { return await BulkInsertAsyncInternal(connection: connection, @@ -455,7 +470,8 @@ public static async Task BulkInsertAsync(this SqlConnection connec batchSize: batchSize, isReturnIdentity: isReturnIdentity, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -473,6 +489,7 @@ public static async Task BulkInsertAsync(this SqlConnection connec /// The flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. This argument will only be used if the 'isReturnIdentity' argument is 'true'. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkInsertAsync(this SqlConnection connection, string tableName, @@ -485,7 +502,8 @@ public static async Task BulkInsertAsync(this SqlConnection connection, int? batchSize = null, bool? isReturnIdentity = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) { return await BulkInsertAsyncInternal(connection: connection, tableName: tableName, @@ -499,7 +517,8 @@ public static async Task BulkInsertAsync(this SqlConnection connection, batchSize: batchSize, isReturnIdentity: isReturnIdentity, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } #endregion @@ -1187,6 +1206,7 @@ internal static int BulkInsertInternal(SqlConnection connection, /// The flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. This argument will only be used if the 'isReturnIdentity' argument is 'true'. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. internal static async Task BulkInsertAsyncInternal(SqlConnection connection, string tableName, @@ -1199,7 +1219,8 @@ internal static async Task BulkInsertAsyncInternal(SqlConnection c int? batchSize = null, bool? isReturnIdentity = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Variables needed @@ -1211,7 +1232,7 @@ internal static async Task BulkInsertAsyncInternal(SqlConnection c if (transaction == null) { // Add the transaction if not present - transaction = (SqlTransaction)(await connection.EnsureOpenAsync()).BeginTransaction(); + transaction = (SqlTransaction)(await connection.EnsureOpenAsync(cancellationToken)).BeginTransaction(); } else { @@ -1222,7 +1243,7 @@ internal static async Task BulkInsertAsyncInternal(SqlConnection c try { // Get the DB Fields - dbFields = dbFields ?? await DbFieldCache.GetAsync(connection, tableName, transaction, true); + dbFields = dbFields ?? await DbFieldCache.GetAsync(connection, tableName, transaction, true, cancellationToken); // Variables needed var identityDbField = dbFields?.FirstOrDefault(dbField => dbField.IsIdentity); @@ -1293,7 +1314,7 @@ internal static async Task BulkInsertAsyncInternal(SqlConnection c tempTableName, fields, dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); } // Set the destinationtable @@ -1318,11 +1339,11 @@ internal static async Task BulkInsertAsyncInternal(SqlConnection c sqlBulkCopy.ColumnMappings.Add(mapItem.SourceColumn, mapItem.DestinationColumn)); // Open the connection and do the operation - connection.EnsureOpen(); + await connection.EnsureOpenAsync(cancellationToken); using (var reader = new DataEntityDataReader(entities)) { - await reader.InitializeAsync(); - await sqlBulkCopy.WriteToServerAsync(reader); + await reader.InitializeAsync(cancellationToken); + await sqlBulkCopy.WriteToServerAsync(reader, cancellationToken); recordsAffected = reader.RecordsAffected; } @@ -1338,13 +1359,13 @@ internal static async Task BulkInsertAsyncInternal(SqlConnection c dbSetting); // Execute the SQL - using (var reader = (DbDataReader)(await connection.ExecuteReaderAsync(sql, commandTimeout: bulkCopyTimeout, transaction: transaction))) + using (var reader = (DbDataReader)(await connection.ExecuteReaderAsync(sql, commandTimeout: bulkCopyTimeout, transaction: transaction, cancellationToken: cancellationToken))) { var func = Compiler.GetPropertySetterFunc(identityDbField.Name); var list = entities.AsList(); - while (await reader.ReadAsync()) + while (await reader.ReadAsync(cancellationToken)) { - var value = Converter.DbNullToNull(await reader.GetFieldValueAsync(0)); + var value = Converter.DbNullToNull(await reader.GetFieldValueAsync(0, cancellationToken)); var entity = list[result]; func(entity, value); result++; @@ -1353,7 +1374,7 @@ internal static async Task BulkInsertAsyncInternal(SqlConnection c // Drop the table after used sql = GetDropTemporaryTableSqlText(tempTableName, dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); } else { @@ -1410,6 +1431,7 @@ internal static async Task BulkInsertAsyncInternal(SqlConnection c /// The flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. This argument will only be used if the 'isReturnIdentity' argument is 'true'. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. internal static async Task BulkInsertAsyncInternal(SqlConnection connection, string tableName, @@ -1422,7 +1444,8 @@ internal static async Task BulkInsertAsyncInternal(SqlConnection connection int? batchSize = null, bool? isReturnIdentity = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) { // Variables needed var dbSetting = connection.GetDbSetting(); @@ -1433,7 +1456,7 @@ internal static async Task BulkInsertAsyncInternal(SqlConnection connection if (transaction == null) { // Add the transaction if not present - transaction = (SqlTransaction)(await connection.EnsureOpenAsync()).BeginTransaction(); + transaction = (SqlTransaction)(await connection.EnsureOpenAsync(cancellationToken)).BeginTransaction(); } else { @@ -1444,7 +1467,7 @@ internal static async Task BulkInsertAsyncInternal(SqlConnection connection try { // Get the DB Fields - dbFields = dbFields ?? await DbFieldCache.GetAsync(connection, tableName, transaction, true); + dbFields = dbFields ?? await DbFieldCache.GetAsync(connection, tableName, transaction, true, cancellationToken); // Variables needed var identityDbField = dbFields?.FirstOrDefault(dbField => dbField.IsIdentity); @@ -1516,7 +1539,7 @@ internal static async Task BulkInsertAsyncInternal(SqlConnection connection tempTableName, fields, dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); } // Set the destinationtable @@ -1541,8 +1564,8 @@ internal static async Task BulkInsertAsyncInternal(SqlConnection connection sqlBulkCopy.ColumnMappings.Add(mapItem.SourceColumn, mapItem.DestinationColumn)); // Open the connection and do the operation - await connection.EnsureOpenAsync(); - await sqlBulkCopy.WriteToServerAsync(reader); + await connection.EnsureOpenAsync(cancellationToken); + await sqlBulkCopy.WriteToServerAsync(reader, cancellationToken); // Check if this is with pseudo if (withPseudoExecution) @@ -1556,11 +1579,11 @@ internal static async Task BulkInsertAsyncInternal(SqlConnection connection dbSetting); // Execute the SQL - result = await connection.ExecuteNonQueryAsync(sql, commandTimeout: bulkCopyTimeout, transaction: transaction); + result = await connection.ExecuteNonQueryAsync(sql, commandTimeout: bulkCopyTimeout, transaction: transaction, cancellationToken: cancellationToken); // Drop the table after used sql = GetDropTemporaryTableSqlText(tempTableName, dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); } else { @@ -1618,6 +1641,7 @@ internal static async Task BulkInsertAsyncInternal(SqlConnection connection /// The flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. This argument will only be used if the 'isReturnIdentity' argument is 'true'. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. internal static async Task BulkInsertAsyncInternal(SqlConnection connection, string tableName, @@ -1631,7 +1655,8 @@ internal static async Task BulkInsertAsyncInternal(SqlConnection connection int? batchSize = null, bool? isReturnIdentity = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) { // Variables needed var dbSetting = connection.GetDbSetting(); @@ -1642,7 +1667,7 @@ internal static async Task BulkInsertAsyncInternal(SqlConnection connection if (transaction == null) { // Add the transaction if not present - transaction = (SqlTransaction)(await connection.EnsureOpenAsync()).BeginTransaction(); + transaction = (SqlTransaction)(await connection.EnsureOpenAsync(cancellationToken)).BeginTransaction(); } else { @@ -1653,7 +1678,7 @@ internal static async Task BulkInsertAsyncInternal(SqlConnection connection try { // Get the DB Fields - dbFields = dbFields ?? await DbFieldCache.GetAsync(connection, tableName, transaction, true); + dbFields = dbFields ?? await DbFieldCache.GetAsync(connection, tableName, transaction, true, cancellationToken); // Variables needed var identityDbField = dbFields?.FirstOrDefault(dbField => dbField.IsIdentity); @@ -1725,7 +1750,7 @@ internal static async Task BulkInsertAsyncInternal(SqlConnection connection tempTableName, fields, dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); } // Set the destinationtable @@ -1750,14 +1775,14 @@ internal static async Task BulkInsertAsyncInternal(SqlConnection connection sqlBulkCopy.ColumnMappings.Add(mapItem.SourceColumn, mapItem.DestinationColumn)); // Open the connection and do the operation - await connection.EnsureOpenAsync(); + await connection.EnsureOpenAsync(cancellationToken); if (rowState.HasValue == true) { - await sqlBulkCopy.WriteToServerAsync(dataTable, rowState.Value); + await sqlBulkCopy.WriteToServerAsync(dataTable, rowState.Value, cancellationToken); } else { - await sqlBulkCopy.WriteToServerAsync(dataTable); + await sqlBulkCopy.WriteToServerAsync(dataTable, cancellationToken); } // Check if this is with pseudo @@ -1777,11 +1802,11 @@ internal static async Task BulkInsertAsyncInternal(SqlConnection connection // Identify the column if (column?.ReadOnly == false) { - using (var reader = (DbDataReader)(await connection.ExecuteReaderAsync(sql, commandTimeout: bulkCopyTimeout, transaction: transaction))) + using (var reader = (DbDataReader)(await connection.ExecuteReaderAsync(sql, commandTimeout: bulkCopyTimeout, transaction: transaction, cancellationToken: cancellationToken))) { - while (await reader.ReadAsync()) + while (await reader.ReadAsync(cancellationToken)) { - var value = Converter.DbNullToNull(await reader.GetFieldValueAsync(0)); + var value = Converter.DbNullToNull(await reader.GetFieldValueAsync(0, cancellationToken)); dataTable.Rows[result][column] = value; result++; } @@ -1789,12 +1814,12 @@ internal static async Task BulkInsertAsyncInternal(SqlConnection connection } else { - result = await connection.ExecuteNonQueryAsync(sql, commandTimeout: bulkCopyTimeout, transaction: transaction); + result = await connection.ExecuteNonQueryAsync(sql, commandTimeout: bulkCopyTimeout, transaction: transaction, cancellationToken: cancellationToken); } // Drop the table after used sql = GetDropTemporaryTableSqlText(tempTableName, dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); } } else diff --git a/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/System.Data.SqlClient/SqlConnection/BulkMerge.cs b/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/System.Data.SqlClient/SqlConnection/BulkMerge.cs index f110df3d8..12cdfc02e 100644 --- a/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/System.Data.SqlClient/SqlConnection/BulkMerge.cs +++ b/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/System.Data.SqlClient/SqlConnection/BulkMerge.cs @@ -7,6 +7,7 @@ using System.Data.SqlClient; using System.Linq; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -303,6 +304,7 @@ public static int BulkMerge(this SqlConnection connection, /// The flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkMergeAsync(this SqlConnection connection, IEnumerable entities, @@ -314,7 +316,8 @@ public static async Task BulkMergeAsync(this SqlConnection connect int? batchSize = null, bool? isReturnIdentity = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { return await BulkMergeAsyncInternal(connection: connection, @@ -328,7 +331,8 @@ public static async Task BulkMergeAsync(this SqlConnection connect batchSize: batchSize, isReturnIdentity: isReturnIdentity, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -347,6 +351,7 @@ public static async Task BulkMergeAsync(this SqlConnection connect /// The flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkMergeAsync(this SqlConnection connection, string tableName, @@ -359,7 +364,8 @@ public static async Task BulkMergeAsync(this SqlConnection connect int? batchSize = null, bool? isReturnIdentity = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { return await BulkMergeAsyncInternal(connection: connection, @@ -373,7 +379,8 @@ public static async Task BulkMergeAsync(this SqlConnection connect batchSize: batchSize, isReturnIdentity: isReturnIdentity, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -390,6 +397,7 @@ public static async Task BulkMergeAsync(this SqlConnection connect /// The size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkMergeAsync(this SqlConnection connection, DbDataReader reader, @@ -400,7 +408,8 @@ public static async Task BulkMergeAsync(this SqlConnection connect int? bulkCopyTimeout = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { return await BulkMergeAsyncInternal(connection: connection, @@ -414,7 +423,8 @@ public static async Task BulkMergeAsync(this SqlConnection connect batchSize: batchSize, isReturnIdentity: false, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } #endregion @@ -435,6 +445,7 @@ public static async Task BulkMergeAsync(this SqlConnection connect /// The size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkMergeAsync(this SqlConnection connection, string tableName, @@ -446,7 +457,8 @@ public static async Task BulkMergeAsync(this SqlConnection connection, int? bulkCopyTimeout = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) { return await BulkMergeAsyncInternal(connection: connection, tableName: tableName, @@ -459,7 +471,8 @@ public static async Task BulkMergeAsync(this SqlConnection connection, batchSize: batchSize, isReturnIdentity: false, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -478,6 +491,7 @@ public static async Task BulkMergeAsync(this SqlConnection connection, /// The flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkMergeAsync(this SqlConnection connection, DataTable dataTable, @@ -490,7 +504,8 @@ public static async Task BulkMergeAsync(this SqlConnection connect int? batchSize = null, bool? isReturnIdentity = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { return await BulkMergeAsyncInternal(connection: connection, @@ -505,7 +520,8 @@ public static async Task BulkMergeAsync(this SqlConnection connect batchSize: batchSize, isReturnIdentity: isReturnIdentity, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -524,6 +540,7 @@ public static async Task BulkMergeAsync(this SqlConnection connect /// The flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkMergeAsync(this SqlConnection connection, string tableName, @@ -537,7 +554,8 @@ public static async Task BulkMergeAsync(this SqlConnection connection, int? batchSize = null, bool? isReturnIdentity = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) { return await BulkMergeAsyncInternal(connection: connection, tableName: tableName, @@ -551,7 +569,8 @@ public static async Task BulkMergeAsync(this SqlConnection connection, batchSize: batchSize, isReturnIdentity: isReturnIdentity, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } #endregion @@ -573,6 +592,7 @@ public static async Task BulkMergeAsync(this SqlConnection connection, /// The flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. internal static int BulkMergeInternal(SqlConnection connection, string tableName, @@ -788,6 +808,7 @@ internal static int BulkMergeInternal(SqlConnection connection, /// The flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. internal static int BulkMergeInternal(SqlConnection connection, string tableName, @@ -984,6 +1005,7 @@ internal static int BulkMergeInternal(SqlConnection connection, /// The flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. internal static int BulkMergeInternal(SqlConnection connection, string tableName, @@ -1203,6 +1225,7 @@ internal static int BulkMergeInternal(SqlConnection connection, /// The flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. internal static async Task BulkMergeAsyncInternal(SqlConnection connection, string tableName, @@ -1215,7 +1238,8 @@ internal static async Task BulkMergeAsyncInternal(SqlConnection co int? batchSize = null, bool? isReturnIdentity = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { // Variables @@ -1227,7 +1251,7 @@ internal static async Task BulkMergeAsyncInternal(SqlConnection co if (transaction == null) { // Add the transaction if not present - transaction = (SqlTransaction)(await connection.EnsureOpenAsync()).BeginTransaction(); + transaction = (SqlTransaction)(await connection.EnsureOpenAsync(cancellationToken)).BeginTransaction(); } else { @@ -1250,7 +1274,7 @@ internal static async Task BulkMergeAsyncInternal(SqlConnection co try { // Get the DB Fields - var dbFields = await DbFieldCache.GetAsync(connection, tableName, transaction, true); + var dbFields = await DbFieldCache.GetAsync(connection, tableName, transaction, true, cancellationToken); // Variables needed var entityFields = FieldCache.Get().Select(f => f.Name); @@ -1299,7 +1323,7 @@ internal static async Task BulkMergeAsyncInternal(SqlConnection co tempTableName, fields, dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); // Set the options to KeepIdentity if needed if (options == null && @@ -1318,24 +1342,25 @@ internal static async Task BulkMergeAsyncInternal(SqlConnection co fields?.Any(field => string.Equals(field.Name, dbField.Name, StringComparison.OrdinalIgnoreCase)) == true); // Do the bulk insertion first - await BulkInsertAsyncInternal(connection, - tempTableName, - entities, - filteredDbFields, - mappings, - options, - null, - bulkCopyTimeout, - batchSize, - false, - false, - transaction); + await BulkInsertAsyncInternal(connection: connection, + tableName: tempTableName, + entities: entities, + dbFields: filteredDbFields, + mappings: mappings, + options: options, + hints: hints, + bulkCopyTimeout: bulkCopyTimeout, + batchSize: batchSize, + isReturnIdentity: false, + usePhysicalPseudoTempTable: false, + transaction, + cancellationToken: cancellationToken); // Create the clustered index sql = GetCreateTemporaryTableClusteredIndexSqlText(tempTableName, qualifiers, dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); // Merge the actual merge sql = GetBulkMergeSqlText(tableName, @@ -1351,17 +1376,17 @@ await BulkInsertAsyncInternal(connection, // Identity if the identity is to return if (isReturnIdentity != true) { - result = await connection.ExecuteNonQueryAsync(sql, commandTimeout: bulkCopyTimeout, transaction: transaction); + result = await connection.ExecuteNonQueryAsync(sql, commandTimeout: bulkCopyTimeout, transaction: transaction, cancellationToken: cancellationToken); } else { - using (var reader = (DbDataReader)(await connection.ExecuteReaderAsync(sql, commandTimeout: bulkCopyTimeout, transaction: transaction))) + using (var reader = (DbDataReader)(await connection.ExecuteReaderAsync(sql, commandTimeout: bulkCopyTimeout, transaction: transaction, cancellationToken: cancellationToken))) { var func = Compiler.GetPropertySetterFunc(identityDbField.Name); var list = entities.AsList(); - while (await reader.ReadAsync()) + while (await reader.ReadAsync(cancellationToken)) { - var value = Converter.DbNullToNull(await reader.GetFieldValueAsync(0)); + var value = Converter.DbNullToNull(await reader.GetFieldValueAsync(0, cancellationToken)); var entity = list[result]; func(entity, value); result++; @@ -1371,7 +1396,7 @@ await BulkInsertAsyncInternal(connection, // Drop the table after used sql = GetDropTemporaryTableSqlText(tempTableName, dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); // Commit the transaction if (hasTransaction == false) @@ -1418,6 +1443,7 @@ await BulkInsertAsyncInternal(connection, /// The flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. internal static async Task BulkMergeAsyncInternal(SqlConnection connection, string tableName, @@ -1430,7 +1456,8 @@ internal static async Task BulkMergeAsyncInternal(SqlConnection connection, int? batchSize = null, bool? isReturnIdentity = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) { // Variables var dbSetting = connection.GetDbSetting(); @@ -1441,7 +1468,7 @@ internal static async Task BulkMergeAsyncInternal(SqlConnection connection, if (transaction == null) { // Add the transaction if not present - transaction = (SqlTransaction)(await connection.EnsureOpenAsync()).BeginTransaction(); + transaction = (SqlTransaction)(await connection.EnsureOpenAsync(cancellationToken)).BeginTransaction(); } else { @@ -1464,7 +1491,7 @@ internal static async Task BulkMergeAsyncInternal(SqlConnection connection, try { // Get the DB Fields - var dbFields = await DbFieldCache.GetAsync(connection, tableName, transaction, true); + var dbFields = await DbFieldCache.GetAsync(connection, tableName, transaction, true, cancellationToken); // Variables needed var readerFields = Enumerable.Range(0, reader.FieldCount) @@ -1514,7 +1541,7 @@ internal static async Task BulkMergeAsyncInternal(SqlConnection connection, tempTableName, fields, dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); // Set the options to KeepIdentity if needed if (options == null && @@ -1533,24 +1560,25 @@ internal static async Task BulkMergeAsyncInternal(SqlConnection connection, fields?.Any(field => string.Equals(field.Name, dbField.Name, StringComparison.OrdinalIgnoreCase)) == true); // Do the bulk insertion first - await BulkInsertAsyncInternal(connection, - tempTableName, - reader, - filteredDbFields, - mappings, - options, - null, - bulkCopyTimeout, - batchSize, - false, - false, - transaction); + await BulkInsertAsyncInternal(connection: connection, + tableName: tempTableName, + reader: reader, + dbFields: filteredDbFields, + mappings: mappings, + options: options, + hints: hints, + bulkCopyTimeout: bulkCopyTimeout, + batchSize: batchSize, + isReturnIdentity: false, + usePhysicalPseudoTempTable: false, + transaction, + cancellationToken: cancellationToken); // Create the clustered index sql = GetCreateTemporaryTableClusteredIndexSqlText(tempTableName, qualifiers, dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); // Merge the actual merge sql = GetBulkMergeSqlText(tableName, @@ -1562,11 +1590,11 @@ await BulkInsertAsyncInternal(connection, hints, dbSetting, isReturnIdentity.GetValueOrDefault()); - result = await connection.ExecuteNonQueryAsync(sql, commandTimeout: bulkCopyTimeout, transaction: transaction); + result = await connection.ExecuteNonQueryAsync(sql, commandTimeout: bulkCopyTimeout, transaction: transaction, cancellationToken: cancellationToken); // Drop the table after used sql = GetDropTemporaryTableSqlText(tempTableName, dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); // Commit the transaction if (hasTransaction == false) @@ -1614,6 +1642,7 @@ await BulkInsertAsyncInternal(connection, /// The flags that signify whether the identity values will be returned. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. internal static async Task BulkMergeAsyncInternal(SqlConnection connection, string tableName, @@ -1627,7 +1656,8 @@ internal static async Task BulkMergeAsyncInternal(SqlConnection connection, int? batchSize = null, bool? isReturnIdentity = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) { // Variables var dbSetting = connection.GetDbSetting(); @@ -1638,7 +1668,7 @@ internal static async Task BulkMergeAsyncInternal(SqlConnection connection, if (transaction == null) { // Add the transaction if not present - transaction = (SqlTransaction)(await connection.EnsureOpenAsync()).BeginTransaction(); + transaction = (SqlTransaction)(await connection.EnsureOpenAsync(cancellationToken)).BeginTransaction(); } else { @@ -1661,7 +1691,7 @@ internal static async Task BulkMergeAsyncInternal(SqlConnection connection, try { // Get the DB Fields - var dbFields = await DbFieldCache.GetAsync(connection, tableName, transaction, true); + var dbFields = await DbFieldCache.GetAsync(connection, tableName, transaction, true, cancellationToken); // Variables needed var tableFields = Enumerable.Range(0, dataTable.Columns.Count) @@ -1711,7 +1741,7 @@ internal static async Task BulkMergeAsyncInternal(SqlConnection connection, tempTableName, fields, dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); // Filter the DB Fields var filteredDbFields = dbFields? @@ -1719,25 +1749,26 @@ internal static async Task BulkMergeAsyncInternal(SqlConnection connection, fields?.Any(field => string.Equals(field.Name, dbField.Name, StringComparison.OrdinalIgnoreCase)) == true); // Do the bulk insertion first - await BulkInsertAsyncInternal(connection, - tempTableName, - dataTable, - rowState, - filteredDbFields, - mappings, - options, - null, - bulkCopyTimeout, - batchSize, - false, - false, - transaction); + await BulkInsertAsyncInternal(connection: connection, + tableName: tempTableName, + dataTable: dataTable, + rowState: rowState, + dbFields: filteredDbFields, + mappings: mappings, + options: options, + hints: hints, + bulkCopyTimeout: bulkCopyTimeout, + batchSize: batchSize, + isReturnIdentity: false, + usePhysicalPseudoTempTable: false, + transaction, + cancellationToken: cancellationToken); // Create the clustered index sql = GetCreateTemporaryTableClusteredIndexSqlText(tempTableName, qualifiers, dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); // Set the options to KeepIdentity if needed if (options == null && @@ -1765,11 +1796,11 @@ await BulkInsertAsyncInternal(connection, var column = dataTable.Columns[identityDbField.Name]; if (isReturnIdentity == true && column?.ReadOnly == false) { - using (var reader = (DbDataReader)(await connection.ExecuteReaderAsync(sql, commandTimeout: bulkCopyTimeout, transaction: transaction))) + using (var reader = (DbDataReader)(await connection.ExecuteReaderAsync(sql, commandTimeout: bulkCopyTimeout, transaction: transaction, cancellationToken: cancellationToken))) { - while (await reader.ReadAsync()) + while (await reader.ReadAsync(cancellationToken)) { - var value = Converter.DbNullToNull((await reader.GetFieldValueAsync(0))); + var value = Converter.DbNullToNull((await reader.GetFieldValueAsync(0, cancellationToken))); dataTable.Rows[result][column] = value; result++; } @@ -1777,12 +1808,12 @@ await BulkInsertAsyncInternal(connection, } else { - result = await connection.ExecuteNonQueryAsync(sql, commandTimeout: bulkCopyTimeout, transaction: transaction); + result = await connection.ExecuteNonQueryAsync(sql, commandTimeout: bulkCopyTimeout, transaction: transaction, cancellationToken: cancellationToken); } // Drop the table after used sql = GetDropTemporaryTableSqlText(tempTableName, dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); // Commit the transaction if (hasTransaction == false) diff --git a/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/System.Data.SqlClient/SqlConnection/BulkUpdate.cs b/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/System.Data.SqlClient/SqlConnection/BulkUpdate.cs index 0adf7857f..7bd045f55 100644 --- a/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/System.Data.SqlClient/SqlConnection/BulkUpdate.cs +++ b/RepoDb.Extensions/RepoDb.SqlServer.BulkOperations/RepoDb.SqlServer.BulkOperations/System.Data.SqlClient/SqlConnection/BulkUpdate.cs @@ -6,6 +6,7 @@ using System.Data.SqlClient; using System.Linq; using System.Linq.Expressions; +using System.Threading; using System.Threading.Tasks; namespace RepoDb @@ -295,6 +296,7 @@ public static int BulkUpdate(this SqlConnection connection, /// The size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkUpdateAsync(this SqlConnection connection, IEnumerable entities, @@ -305,12 +307,13 @@ public static async Task BulkUpdateAsync(this SqlConnection connec int? bulkCopyTimeout = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { using (var reader = new DataEntityDataReader(entities)) { - await reader.InitializeAsync(); + await reader.InitializeAsync(cancellationToken); return await BulkUpdateAsyncInternal(connection: connection, tableName: ClassMappedNameCache.Get(), reader: reader, @@ -321,7 +324,8 @@ public static async Task BulkUpdateAsync(this SqlConnection connec bulkCopyTimeout: bulkCopyTimeout, batchSize: batchSize, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } } @@ -340,6 +344,7 @@ public static async Task BulkUpdateAsync(this SqlConnection connec /// The size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkUpdateAsync(this SqlConnection connection, string tableName, @@ -351,12 +356,13 @@ public static async Task BulkUpdateAsync(this SqlConnection connec int? bulkCopyTimeout = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { using (var reader = new DataEntityDataReader(entities)) { - await reader.InitializeAsync(); + await reader.InitializeAsync(cancellationToken); return await BulkUpdateAsyncInternal(connection: connection, tableName: tableName, reader: reader, @@ -367,7 +373,8 @@ public static async Task BulkUpdateAsync(this SqlConnection connec bulkCopyTimeout: bulkCopyTimeout, batchSize: batchSize, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } } @@ -385,6 +392,7 @@ public static async Task BulkUpdateAsync(this SqlConnection connec /// The size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkUpdateAsync(this SqlConnection connection, DbDataReader reader, @@ -395,7 +403,8 @@ public static async Task BulkUpdateAsync(this SqlConnection connec int? bulkCopyTimeout = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { return await BulkUpdateAsyncInternal(connection: connection, @@ -408,7 +417,8 @@ public static async Task BulkUpdateAsync(this SqlConnection connec bulkCopyTimeout: bulkCopyTimeout, batchSize: batchSize, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } #endregion @@ -429,6 +439,7 @@ public static async Task BulkUpdateAsync(this SqlConnection connec /// The size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkUpdateAsync(this SqlConnection connection, string tableName, @@ -440,7 +451,8 @@ public static async Task BulkUpdateAsync(this SqlConnection connection, int? bulkCopyTimeout = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) { return await BulkUpdateAsyncInternal(connection: connection, tableName: tableName, @@ -452,7 +464,8 @@ public static async Task BulkUpdateAsync(this SqlConnection connection, bulkCopyTimeout: bulkCopyTimeout, batchSize: batchSize, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -470,6 +483,7 @@ public static async Task BulkUpdateAsync(this SqlConnection connection, /// The size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkUpdateAsync(this SqlConnection connection, DataTable dataTable, @@ -481,7 +495,8 @@ public static async Task BulkUpdateAsync(this SqlConnection connec int? bulkCopyTimeout = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) where TEntity : class { return await BulkUpdateAsyncInternal(connection: connection, @@ -495,7 +510,8 @@ public static async Task BulkUpdateAsync(this SqlConnection connec bulkCopyTimeout: bulkCopyTimeout, batchSize: batchSize, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } /// @@ -513,6 +529,7 @@ public static async Task BulkUpdateAsync(this SqlConnection connec /// The size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. public static async Task BulkUpdateAsync(this SqlConnection connection, string tableName, @@ -525,7 +542,8 @@ public static async Task BulkUpdateAsync(this SqlConnection connection, int? bulkCopyTimeout = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) { return await BulkUpdateAsyncInternal(connection: connection, tableName: tableName, @@ -538,7 +556,8 @@ public static async Task BulkUpdateAsync(this SqlConnection connection, bulkCopyTimeout: bulkCopyTimeout, batchSize: batchSize, usePhysicalPseudoTempTable: usePhysicalPseudoTempTable, - transaction: transaction); + transaction: transaction, + cancellationToken: cancellationToken); } #endregion @@ -559,6 +578,7 @@ public static async Task BulkUpdateAsync(this SqlConnection connection, /// The size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. internal static int BulkUpdateInternal(SqlConnection connection, string tableName, @@ -752,6 +772,7 @@ internal static int BulkUpdateInternal(SqlConnection connection, /// The size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. internal static int BulkUpdateInternal(SqlConnection connection, string tableName, @@ -947,6 +968,7 @@ internal static int BulkUpdateInternal(SqlConnection connection, /// The size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. internal static async Task BulkUpdateAsyncInternal(SqlConnection connection, string tableName, @@ -958,7 +980,8 @@ internal static async Task BulkUpdateAsyncInternal(SqlConnection connection int? bulkCopyTimeout = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) { // Variables var dbSetting = connection.GetDbSetting(); @@ -969,7 +992,7 @@ internal static async Task BulkUpdateAsyncInternal(SqlConnection connection if (transaction == null) { // Add the transaction if not present - transaction = (SqlTransaction)(await connection.EnsureOpenAsync()).BeginTransaction(); + transaction = (SqlTransaction)(await connection.EnsureOpenAsync(cancellationToken)).BeginTransaction(); } else { @@ -992,7 +1015,7 @@ internal static async Task BulkUpdateAsyncInternal(SqlConnection connection try { // Get the DB Fields - var dbFields = await DbFieldCache.GetAsync(connection, tableName, transaction, true); + var dbFields = await DbFieldCache.GetAsync(connection, tableName, transaction, true, cancellationToken); // Variables needed var readerFields = Enumerable.Range(0, reader.FieldCount) @@ -1042,7 +1065,7 @@ internal static async Task BulkUpdateAsyncInternal(SqlConnection connection tempTableName, fields, dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); // Set the options to KeepIdentity if needed if (options == null && identityDbField?.IsIdentity == true && @@ -1058,24 +1081,25 @@ internal static async Task BulkUpdateAsyncInternal(SqlConnection connection fields?.Any(field => string.Equals(field.Name, dbField.Name, StringComparison.OrdinalIgnoreCase)) == true); // Do the bulk insertion first - await BulkInsertAsyncInternal(connection, - tempTableName, - reader, - filteredDbFields, - mappings, - options, - null, - bulkCopyTimeout, - batchSize, - false, - false, - transaction); + await BulkInsertAsyncInternal(connection: connection, + tableName: tempTableName, + reader: reader, + dbFields: filteredDbFields, + mappings: mappings, + options: options, + hints: hints, + bulkCopyTimeout: bulkCopyTimeout, + batchSize: batchSize, + isReturnIdentity: false, + usePhysicalPseudoTempTable: false, + transaction: transaction, + cancellationToken: cancellationToken); // Create the clustered index sql = GetCreateTemporaryTableClusteredIndexSqlText(tempTableName, qualifiers, dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); // Update the actual update sql = GetBulkUpdateSqlText(tableName, @@ -1086,11 +1110,11 @@ await BulkInsertAsyncInternal(connection, identityDbField?.AsField(), hints, dbSetting); - result = await connection.ExecuteNonQueryAsync(sql, commandTimeout: bulkCopyTimeout, transaction: transaction); + result = await connection.ExecuteNonQueryAsync(sql, commandTimeout: bulkCopyTimeout, transaction: transaction, cancellationToken: cancellationToken); // Drop the table after used sql = GetDropTemporaryTableSqlText(tempTableName, dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); // Commit the transaction if (hasTransaction == false) @@ -1137,6 +1161,7 @@ await BulkInsertAsyncInternal(connection, /// The size per batch to be used. /// The flags that signify whether to create a physical pseudo table. /// The transaction to be used. + /// The object to be used during the asynchronous operation. /// The number of rows affected by the execution. internal static async Task BulkUpdateAsyncInternal(SqlConnection connection, string tableName, @@ -1149,7 +1174,8 @@ internal static async Task BulkUpdateAsyncInternal(SqlConnection connection int? bulkCopyTimeout = null, int? batchSize = null, bool? usePhysicalPseudoTempTable = null, - SqlTransaction transaction = null) + SqlTransaction transaction = null, + CancellationToken cancellationToken = default) { // Variables var dbSetting = connection.GetDbSetting(); @@ -1160,7 +1186,7 @@ internal static async Task BulkUpdateAsyncInternal(SqlConnection connection if (transaction == null) { // Add the transaction if not present - transaction = (SqlTransaction)(await connection.EnsureOpenAsync()).BeginTransaction(); + transaction = (SqlTransaction)(await connection.EnsureOpenAsync(cancellationToken)).BeginTransaction(); } else { @@ -1183,7 +1209,7 @@ internal static async Task BulkUpdateAsyncInternal(SqlConnection connection try { // Get the DB Fields - var dbFields = await DbFieldCache.GetAsync(connection, tableName, transaction, true); + var dbFields = await DbFieldCache.GetAsync(connection, tableName, transaction, true, cancellationToken); // Variables needed var tableFields = Enumerable.Range(0, dataTable.Columns.Count) @@ -1233,7 +1259,7 @@ internal static async Task BulkUpdateAsyncInternal(SqlConnection connection tempTableName, fields, dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); // Set the options to KeepIdentity if needed if (options == null && identityDbField?.IsIdentity == true && @@ -1249,25 +1275,26 @@ internal static async Task BulkUpdateAsyncInternal(SqlConnection connection fields?.Any(field => string.Equals(field.Name, dbField.Name, StringComparison.OrdinalIgnoreCase)) == true); // Do the bulk insertion first - await BulkInsertAsyncInternal(connection, - tempTableName, - dataTable, - rowState, - filteredDbFields, - mappings, - options, - null, - bulkCopyTimeout, - batchSize, - false, - false, - transaction); + await BulkInsertAsyncInternal(connection: connection, + tableName: tempTableName, + dataTable: dataTable, + rowState: rowState, + dbFields: filteredDbFields, + mappings: mappings, + options: options, + hints: hints, + bulkCopyTimeout: bulkCopyTimeout, + batchSize: batchSize, + isReturnIdentity: false, + usePhysicalPseudoTempTable: false, + transaction: transaction, + cancellationToken: cancellationToken); // Create the clustered index sql = GetCreateTemporaryTableClusteredIndexSqlText(tempTableName, qualifiers, dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); // Update the actual update sql = GetBulkUpdateSqlText(tableName, @@ -1278,11 +1305,11 @@ await BulkInsertAsyncInternal(connection, identityDbField?.AsField(), hints, dbSetting); - result = await connection.ExecuteNonQueryAsync(sql, commandTimeout: bulkCopyTimeout, transaction: transaction); + result = await connection.ExecuteNonQueryAsync(sql, commandTimeout: bulkCopyTimeout, transaction: transaction, cancellationToken: cancellationToken); // Drop the table after used sql = GetDropTemporaryTableSqlText(tempTableName, dbSetting); - await connection.ExecuteNonQueryAsync(sql, transaction: transaction); + await connection.ExecuteNonQueryAsync(sql, transaction: transaction, cancellationToken: cancellationToken); // Commit the transaction if (hasTransaction == false) diff --git a/RepoDb.MySql/RepoDb.MySql/DbHelpers/MySqlDbHelper.cs b/RepoDb.MySql/RepoDb.MySql/DbHelpers/MySqlDbHelper.cs index 8f970c6f8..09fa02ee0 100644 --- a/RepoDb.MySql/RepoDb.MySql/DbHelpers/MySqlDbHelper.cs +++ b/RepoDb.MySql/RepoDb.MySql/DbHelpers/MySqlDbHelper.cs @@ -5,7 +5,9 @@ using System; using System.Collections.Generic; using System.Data; +using System.Data.Common; using System.Linq; +using System.Threading; using System.Threading.Tasks; namespace RepoDb.DbHelpers @@ -45,9 +47,9 @@ public MySqlDbHelper(IResolver dbTypeResolver) #region Helpers /// - /// Returns the command text that is being used to extract schema definitions. + /// /// - /// The command text. + /// private string GetCommandText() { return $@"SELECT COLUMN_NAME AS ColumnName @@ -66,9 +68,9 @@ FROM INFORMATION_SCHEMA.COLUMNS } /// - /// Get the list of type names for all blob-types for MySql. + /// /// - /// The list of column type names. + /// private IEnumerable GetBlobTypes() { return new[] @@ -86,11 +88,11 @@ private IEnumerable GetBlobTypes() } /// - /// Converts the object into object. + /// /// - /// The instance of object. - /// The instance of converted object. - private DbField ReaderToDbField(IDataReader reader) + /// + /// + private DbField ReaderToDbField(DbDataReader reader) { var columnType = reader.GetString(4); var excluded = GetBlobTypes(); @@ -114,6 +116,38 @@ private DbField ReaderToDbField(IDataReader reader) reader.GetString(8)); } + /// + /// + /// + /// + /// + /// + private async Task ReaderToDbFieldAsync(DbDataReader reader, + CancellationToken cancellationToken = default) + { + var columnType = await reader.GetFieldValueAsync(4, cancellationToken); + var excluded = GetBlobTypes(); + var size = (int?)null; + if (excluded.Contains(columnType.ToLowerInvariant())) + { + size = null; + } + else + { + size = await reader.IsDBNullAsync(5, cancellationToken) ? (int?)null : + await reader.GetFieldValueAsync(5, cancellationToken); + } + return new DbField(await reader.GetFieldValueAsync(0, cancellationToken), + await reader.GetFieldValueAsync(1, cancellationToken), + await reader.GetFieldValueAsync(2, cancellationToken), + await reader.GetFieldValueAsync(1, cancellationToken), + DbTypeResolver.Resolve(columnType), + size, + await reader.IsDBNullAsync(6, cancellationToken) ? (byte?)null : byte.Parse((await reader.GetFieldValueAsync(6, cancellationToken)).ToString()), + await reader.IsDBNullAsync(7, cancellationToken) ? (byte?)null : byte.Parse((await reader.GetFieldValueAsync(7, cancellationToken)).ToString()), + await reader.GetFieldValueAsync(8, cancellationToken)); + } + #endregion #region Methods @@ -140,7 +174,7 @@ public IEnumerable GetFields(IDbConnection connection, }; // Iterate and extract - using (var reader = connection.ExecuteReader(commandText, param, transaction: transaction)) + using (var reader = (DbDataReader)connection.ExecuteReader(commandText, param, transaction: transaction)) { var dbFields = new List(); @@ -161,11 +195,15 @@ public IEnumerable GetFields(IDbConnection connection, /// The instance of the connection object. /// The name of the target table. /// The transaction object that is currently in used. + /// The object to be used during the asynchronous operation. /// A list of of the target table. public async Task> GetFieldsAsync(IDbConnection connection, string tableName, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { + cancellationToken.ThrowIfCancellationRequested(); + // Variables var commandText = GetCommandText(); var param = new @@ -175,14 +213,15 @@ public async Task> GetFieldsAsync(IDbConnection connection, }; // Iterate and extract - using (var reader = await connection.ExecuteReaderAsync(commandText, param, transaction: transaction)) + using (var reader = (DbDataReader)await connection.ExecuteReaderAsync(commandText, param, transaction: transaction, + cancellationToken: cancellationToken)) { var dbFields = new List(); // Iterate the list of the fields - while (reader.Read()) + while (await reader.ReadAsync(cancellationToken)) { - dbFields.Add(ReaderToDbField(reader)); + dbFields.Add(await ReaderToDbFieldAsync(reader, cancellationToken)); } // Return the list of fields @@ -203,7 +242,7 @@ public async Task> GetFieldsAsync(IDbConnection connection, public object GetScopeIdentity(IDbConnection connection, IDbTransaction transaction = null) { - return connection.ExecuteScalar("SELECT LAST_INSERT_ID();"); + return connection.ExecuteScalar("SELECT LAST_INSERT_ID();", transaction: transaction); } /// @@ -211,11 +250,14 @@ public object GetScopeIdentity(IDbConnection connection, /// /// The instance of the connection object. /// The transaction object that is currently in used. + /// The object to be used during the asynchronous operation. /// The newly generated identity from the database. public async Task GetScopeIdentityAsync(IDbConnection connection, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { - return await connection.ExecuteScalarAsync("SELECT LAST_INSERT_ID();"); + return await connection.ExecuteScalarAsync("SELECT LAST_INSERT_ID();", transaction: transaction, + cancellationToken: cancellationToken); } #endregion diff --git a/RepoDb.MySqlConnector/RepoDb.MySqlConnector/DbHelpers/MySqlConnectorDbHelper.cs b/RepoDb.MySqlConnector/RepoDb.MySqlConnector/DbHelpers/MySqlConnectorDbHelper.cs index 80dd582d8..60fc8e7dd 100644 --- a/RepoDb.MySqlConnector/RepoDb.MySqlConnector/DbHelpers/MySqlConnectorDbHelper.cs +++ b/RepoDb.MySqlConnector/RepoDb.MySqlConnector/DbHelpers/MySqlConnectorDbHelper.cs @@ -5,7 +5,9 @@ using System; using System.Collections.Generic; using System.Data; +using System.Data.Common; using System.Linq; +using System.Threading; using System.Threading.Tasks; namespace RepoDb.DbHelpers @@ -45,9 +47,9 @@ public MySqlConnectorDbHelper(IResolver dbTypeResolver) #region Helpers /// - /// Returns the command text that is being used to extract schema definitions. + /// /// - /// The command text. + /// private string GetCommandText() { return $@"SELECT COLUMN_NAME AS ColumnName @@ -66,9 +68,9 @@ FROM INFORMATION_SCHEMA.COLUMNS } /// - /// Get the list of type names for all blob-types for MySql. + /// /// - /// The list of column type names. + /// private IEnumerable GetBlobTypes() { return new[] @@ -86,11 +88,11 @@ private IEnumerable GetBlobTypes() } /// - /// Converts the object into object. + /// /// - /// The instance of object. - /// The instance of converted object. - private DbField ReaderToDbField(IDataReader reader) + /// + /// + private DbField ReaderToDbField(DbDataReader reader) { var columnType = reader.GetString(4); var excluded = GetBlobTypes(); @@ -114,6 +116,38 @@ private DbField ReaderToDbField(IDataReader reader) reader.GetString(8)); } + /// + /// + /// + /// + /// + /// + private async Task ReaderToDbFieldAsync(DbDataReader reader, + CancellationToken cancellationToken = default) + { + var columnType = await reader.GetFieldValueAsync(4, cancellationToken); + var excluded = GetBlobTypes(); + var size = (int?)null; + if (excluded.Contains(columnType.ToLowerInvariant())) + { + size = null; + } + else + { + size = await reader.IsDBNullAsync(5, cancellationToken) ? (int?)null : + await reader.GetFieldValueAsync(5, cancellationToken); + } + return new DbField(await reader.GetFieldValueAsync(0, cancellationToken), + await reader.GetFieldValueAsync(1, cancellationToken), + await reader.GetFieldValueAsync(2, cancellationToken), + await reader.GetFieldValueAsync(1, cancellationToken), + DbTypeResolver.Resolve(columnType), + size, + await reader.IsDBNullAsync(6, cancellationToken) ? (byte?)null : byte.Parse((await reader.GetFieldValueAsync(6, cancellationToken)).ToString()), + await reader.IsDBNullAsync(7, cancellationToken) ? (byte?)null : byte.Parse((await reader.GetFieldValueAsync(7, cancellationToken)).ToString()), + await reader.GetFieldValueAsync(8, cancellationToken)); + } + #endregion #region Methods @@ -140,7 +174,7 @@ public IEnumerable GetFields(IDbConnection connection, }; // Iterate and extract - using (var reader = connection.ExecuteReader(commandText, param, transaction: transaction)) + using (var reader = (DbDataReader)connection.ExecuteReader(commandText, param, transaction: transaction)) { var dbFields = new List(); @@ -161,11 +195,15 @@ public IEnumerable GetFields(IDbConnection connection, /// The instance of the connection object. /// The name of the target table. /// The transaction object that is currently in used. + /// The object to be used during the asynchronous operation. /// A list of of the target table. public async Task> GetFieldsAsync(IDbConnection connection, string tableName, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { + cancellationToken.ThrowIfCancellationRequested(); + // Variables var commandText = GetCommandText(); var param = new @@ -175,14 +213,15 @@ public async Task> GetFieldsAsync(IDbConnection connection, }; // Iterate and extract - using (var reader = await connection.ExecuteReaderAsync(commandText, param, transaction: transaction)) + using (var reader = (DbDataReader)await connection.ExecuteReaderAsync(commandText, param, transaction: transaction, + cancellationToken: cancellationToken)) { var dbFields = new List(); // Iterate the list of the fields - while (reader.Read()) + while (await reader.ReadAsync(cancellationToken)) { - dbFields.Add(ReaderToDbField(reader)); + dbFields.Add(await ReaderToDbFieldAsync(reader, cancellationToken)); } // Return the list of fields @@ -203,7 +242,7 @@ public async Task> GetFieldsAsync(IDbConnection connection, public object GetScopeIdentity(IDbConnection connection, IDbTransaction transaction = null) { - return connection.ExecuteScalar("SELECT LAST_INSERT_ID();"); + return connection.ExecuteScalar("SELECT LAST_INSERT_ID();", transaction: transaction); } /// @@ -211,11 +250,14 @@ public object GetScopeIdentity(IDbConnection connection, /// /// The instance of the connection object. /// The transaction object that is currently in used. + /// The object to be used during the asynchronous operation. /// The newly generated identity from the database. public async Task GetScopeIdentityAsync(IDbConnection connection, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { - return await connection.ExecuteScalarAsync("SELECT LAST_INSERT_ID();"); + return await connection.ExecuteScalarAsync("SELECT LAST_INSERT_ID();", transaction: transaction, + cancellationToken: cancellationToken); } #endregion diff --git a/RepoDb.PostgreSql/RepoDb.PostgreSql/DbHelpers/PostgreSqlDbHelper.cs b/RepoDb.PostgreSql/RepoDb.PostgreSql/DbHelpers/PostgreSqlDbHelper.cs index cff7842a1..f9fe46e90 100644 --- a/RepoDb.PostgreSql/RepoDb.PostgreSql/DbHelpers/PostgreSqlDbHelper.cs +++ b/RepoDb.PostgreSql/RepoDb.PostgreSql/DbHelpers/PostgreSqlDbHelper.cs @@ -5,6 +5,8 @@ using System; using System.Collections.Generic; using System.Data; +using System.Data.Common; +using System.Threading; using System.Threading.Tasks; namespace RepoDb.DbHelpers @@ -44,9 +46,9 @@ public PostgreSqlDbHelper(IResolver dbTypeResolver) #region Helpers /// - /// Returns the command text that is being used to extract schema definitions. + /// /// - /// The command text. + /// private string GetCommandText() { return @" @@ -75,11 +77,11 @@ JOIN information_schema.constraint_column_usage AS CCU USING (constraint_schema, } /// - /// Converts the object into object. + /// /// - /// The instance of object. - /// The instance of converted object. - private DbField ReaderToDbField(IDataReader reader) + /// + /// + private DbField ReaderToDbField(DbDataReader reader) { return new DbField(reader.GetString(0), reader.IsDBNull(1) ? false : reader.GetBoolean(1), @@ -92,6 +94,26 @@ private DbField ReaderToDbField(IDataReader reader) reader.IsDBNull(4) ? "text" : reader.GetString(4)); } + /// + /// + /// + /// + /// + /// + private async Task ReaderToDbFieldAsync(DbDataReader reader, + CancellationToken cancellationToken = default) + { + return new DbField(await reader.GetFieldValueAsync(0, cancellationToken), + await reader.IsDBNullAsync(1, cancellationToken) ? false : await reader.GetFieldValueAsync(1, cancellationToken), + await reader.IsDBNullAsync(2, cancellationToken) ? false : await reader.GetFieldValueAsync(2, cancellationToken), + await reader.IsDBNullAsync(3, cancellationToken) ? false : await reader.GetFieldValueAsync(3, cancellationToken), + await reader.IsDBNullAsync(4, cancellationToken) ? DbTypeResolver.Resolve("text") : DbTypeResolver.Resolve(await reader.GetFieldValueAsync(4, cancellationToken)), + null, + null, + null, + await reader.IsDBNullAsync(4) ? "text" : reader.GetString(4)); + } + #endregion #region Methods @@ -118,7 +140,7 @@ public IEnumerable GetFields(IDbConnection connection, }; // Iterate and extract - using (var reader = connection.ExecuteReader(commandText, param, transaction: transaction)) + using (var reader = (DbDataReader)connection.ExecuteReader(commandText, param, transaction: transaction)) { var dbFields = new List(); @@ -139,10 +161,12 @@ public IEnumerable GetFields(IDbConnection connection, /// The instance of the connection object. /// The name of the target table. /// The transaction object that is currently in used. + /// The object to be used during the asynchronous operation. /// A list of of the target table. public async Task> GetFieldsAsync(IDbConnection connection, string tableName, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Variables var commandText = GetCommandText(); @@ -153,14 +177,15 @@ public async Task> GetFieldsAsync(IDbConnection connection, }; // Iterate and extract - using (var reader = await connection.ExecuteReaderAsync(commandText, param, transaction: transaction)) + using (var reader = (DbDataReader)await connection.ExecuteReaderAsync(commandText, param, transaction: transaction, + cancellationToken: cancellationToken)) { var dbFields = new List(); // Iterate the list of the fields - while (reader.Read()) + while (await reader.ReadAsync(cancellationToken)) { - dbFields.Add(ReaderToDbField(reader)); + dbFields.Add(await ReaderToDbFieldAsync(reader)); } // Return the list of fields @@ -182,7 +207,7 @@ public object GetScopeIdentity(IDbConnection connection, IDbTransaction transaction = null) { // TODO: May fail with trigger? - return connection.ExecuteScalar("SELECT lastval();"); + return connection.ExecuteScalar("SELECT lastval();", transaction: transaction); } /// @@ -190,12 +215,15 @@ public object GetScopeIdentity(IDbConnection connection, /// /// The instance of the connection object. /// The transaction object that is currently in used. + /// The object to be used during the asynchronous operation. /// The newly generated identity from the database. public async Task GetScopeIdentityAsync(IDbConnection connection, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // TODO: May fail with trigger? - return await connection.ExecuteScalarAsync("SELECT lastval();"); + return await connection.ExecuteScalarAsync("SELECT lastval();", transaction: transaction, + cancellationToken: cancellationToken); } #endregion diff --git a/RepoDb.SqLite/RepoDb.SqLite/DbHelpers/SqLiteDbHelper.cs b/RepoDb.SqLite/RepoDb.SqLite/DbHelpers/SqLiteDbHelper.cs index 10c3251d1..6907836f1 100644 --- a/RepoDb.SqLite/RepoDb.SqLite/DbHelpers/SqLiteDbHelper.cs +++ b/RepoDb.SqLite/RepoDb.SqLite/DbHelpers/SqLiteDbHelper.cs @@ -5,6 +5,7 @@ using System.Data; using System.Data.Common; using System.Linq; +using System.Threading; using System.Threading.Tasks; namespace RepoDb.DbHelpers @@ -43,22 +44,22 @@ public SqLiteDbHelper(IDbSetting dbSetting, #region Helpers /// - /// Returns the command text that is being used to extract schema definitions. + /// /// - /// The name of the target table. - /// The command text. + /// + /// private string GetCommandText(string tableName) { return $"pragma table_info({DataEntityExtension.GetTableName(tableName)});"; } /// - /// Converts the object into object. + /// /// - /// The instance of object. - /// The name of the identity column. - /// The instance of converted object. - private DbField ReaderToDbField(IDataReader reader, + /// + /// + /// + private DbField ReaderToDbField(DbDataReader reader, string identityFieldName) { return new DbField(reader.GetString(1), @@ -73,13 +74,35 @@ private DbField ReaderToDbField(IDataReader reader, } /// - /// Gets the list of of the table. + /// /// - /// The type of object. - /// The instance of the connection object. - /// The name of the target table. - /// The transaction object that is currently in used. - /// A list of of the target table. + /// + /// + /// + /// + private async Task ReaderToDbFieldAsync(DbDataReader reader, + string identityFieldName, + CancellationToken cancellationToken = default) + { + return new DbField(await reader.GetFieldValueAsync(1, cancellationToken), + await reader.IsDBNullAsync(5, cancellationToken) ? false : reader.GetBoolean(5), + string.Equals(await reader.GetFieldValueAsync(1, cancellationToken), identityFieldName, StringComparison.OrdinalIgnoreCase), + await reader.IsDBNullAsync(3, cancellationToken) ? true : await reader.GetFieldValueAsync(3, cancellationToken) == false, + await reader.IsDBNullAsync(2, cancellationToken) ? DbTypeResolver.Resolve("text") : DbTypeResolver.Resolve(await reader.GetFieldValueAsync(2, cancellationToken)), + null, + null, + null, + null); + } + + /// + /// + /// + /// + /// + /// + /// + /// private string GetIdentityFieldName(TDbConnection connection, string tableName, IDbTransaction transaction = null) @@ -90,6 +113,45 @@ private string GetIdentityFieldName(TDbConnection connection, var sql = connection.ExecuteScalar(commandText: commandText, param: new { TableName = DataEntityExtension.GetTableName(tableName).AsUnquoted(DbSetting) }, transaction: transaction); + + // Return + return GetIdentityFieldNameInternal(sql); + } + + /// + /// + /// + /// + /// + /// + /// + /// + /// + private async Task GetIdentityFieldNameAsync(TDbConnection connection, + string tableName, + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) + where TDbConnection : IDbConnection + { + // Sql text + var commandText = "SELECT sql FROM [sqlite_master] WHERE name = @TableName AND type = 'table';"; + var sql = await connection.ExecuteScalarAsync(commandText: commandText, + param: new { TableName = DataEntityExtension.GetTableName(tableName).AsUnquoted(DbSetting) }, + transaction: transaction, + cancellationToken: cancellationToken); + + // Return + return GetIdentityFieldNameInternal(sql); + } + + /// + /// + /// + /// + /// + private string GetIdentityFieldNameInternal(string sql) + { + // Sql text var fields = ParseTableFieldsFromSql(sql); // Iterate the fields @@ -109,10 +171,10 @@ private string GetIdentityFieldName(TDbConnection connection, } /// - /// Returns true if the field is an identity based on the definition from link (https://sqlite.org/autoinc.html). + /// /// - /// The field to identify. - /// True if the field is an identity. + /// + /// private bool IsIdentity(string field) => field.ToUpper().Contains("AUTOINCREMENT") || field.ToUpper().Contains("INTEGER PRIMARY KEY") || @@ -120,10 +182,10 @@ private bool IsIdentity(string field) => (field.ToUpper().Contains("INTEGER") && field.ToUpper().Contains("PRIMARY") && field.ToUpper().Contains("KEY")); /// - /// Parses the table sql and return the list of the fields. + /// /// - /// The sql to be parsed. - /// The list of the fields. + /// + /// private string[] ParseTableFieldsFromSql(string sql) { if (string.IsNullOrEmpty(sql)) @@ -164,7 +226,7 @@ public IEnumerable GetFields(IDbConnection connection, var commandText = GetCommandText(tableName); // Iterate and extract - using (var reader = connection.ExecuteReader(commandText, transaction: transaction)) + using (var reader = (DbDataReader)connection.ExecuteReader(commandText, transaction: transaction)) { var dbFields = new List(); var identity = GetIdentityFieldName(connection, tableName, transaction); @@ -186,24 +248,26 @@ public IEnumerable GetFields(IDbConnection connection, /// The instance of the connection object. /// The name of the target table. /// The transaction object that is currently in used. + /// The object to be used during the asynchronous operation. /// A list of of the target table. public async Task> GetFieldsAsync(IDbConnection connection, string tableName, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Variables var commandText = GetCommandText(tableName); // Iterate and extract - using (var reader = await connection.ExecuteReaderAsync(commandText, transaction: transaction)) + using (var reader = (DbDataReader)await connection.ExecuteReaderAsync(commandText, transaction: transaction, cancellationToken: cancellationToken)) { var dbFields = new List(); - var identity = GetIdentityFieldName(connection, tableName, transaction); + var identity = await GetIdentityFieldNameAsync(connection, tableName, transaction, cancellationToken); // Iterate the list of the fields - while (reader.Read()) + while (await reader.ReadAsync(cancellationToken)) { - dbFields.Add(ReaderToDbField(reader, identity)); + dbFields.Add(await ReaderToDbFieldAsync(reader, identity, cancellationToken)); } // Return the list of fields @@ -224,7 +288,7 @@ public async Task> GetFieldsAsync(IDbConnection connection, public object GetScopeIdentity(IDbConnection connection, IDbTransaction transaction = null) { - return connection.ExecuteScalar("SELECT last_insert_rowid();"); + return connection.ExecuteScalar("SELECT last_insert_rowid();", transaction: transaction); } /// @@ -232,11 +296,14 @@ public object GetScopeIdentity(IDbConnection connection, /// /// The instance of the connection object. /// The transaction object that is currently in used. + /// The object to be used during the asynchronous operation. /// The newly generated identity from the database. public async Task GetScopeIdentityAsync(IDbConnection connection, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { - return await connection.ExecuteScalarAsync("SELECT last_insert_rowid();"); + return await connection.ExecuteScalarAsync("SELECT last_insert_rowid();", transaction: transaction, + cancellationToken: cancellationToken); } #endregion diff --git a/RepoDb.SqlServer/RepoDb.SqlServer/DbHelpers/SqlServerDbHelper.cs b/RepoDb.SqlServer/RepoDb.SqlServer/DbHelpers/SqlServerDbHelper.cs index 167cd49a2..c3eed25e4 100644 --- a/RepoDb.SqlServer/RepoDb.SqlServer/DbHelpers/SqlServerDbHelper.cs +++ b/RepoDb.SqlServer/RepoDb.SqlServer/DbHelpers/SqlServerDbHelper.cs @@ -4,6 +4,8 @@ using System; using System.Collections.Generic; using System.Data; +using System.Data.Common; +using System.Threading; using System.Threading.Tasks; namespace RepoDb.DbHelpers @@ -41,9 +43,9 @@ public SqlServerDbHelper(IResolver dbTypeResolver) #region Helpers /// - /// Returns the command text that is being used to extract schema definitions. + /// /// - /// The command text. + /// private string GetCommandText() { return @" @@ -94,11 +96,11 @@ FROM [sys].[columns] SC } /// - /// Converts the object into object. + /// /// - /// The instance of object. - /// The instance of converted object. - private DbField ReaderToDbField(IDataReader reader) + /// + /// + private DbField ReaderToDbField(DbDataReader reader) { return new DbField(reader.GetString(0), reader.IsDBNull(1) ? false : reader.GetBoolean(1), @@ -110,7 +112,27 @@ private DbField ReaderToDbField(IDataReader reader) reader.IsDBNull(7) ? (byte?)0 : reader.GetByte(7), reader.IsDBNull(7) ? "text" : reader.GetString(4)); } - + + /// + /// + /// + /// + /// + /// + private async Task ReaderToDbFieldAsync(DbDataReader reader, + CancellationToken cancellationToken = default) + { + return new DbField(await reader.GetFieldValueAsync(0, cancellationToken), + await reader.IsDBNullAsync(1, cancellationToken) ? false : await reader.GetFieldValueAsync(1, cancellationToken), + await reader.IsDBNullAsync(2, cancellationToken) ? false : await reader.GetFieldValueAsync(2, cancellationToken), + await reader.IsDBNullAsync(3, cancellationToken) ? false : await reader.GetFieldValueAsync(3, cancellationToken), + await reader.IsDBNullAsync(4, cancellationToken) ? DbTypeResolver.Resolve("text") : DbTypeResolver.Resolve(await reader.GetFieldValueAsync(4, cancellationToken)), + await reader.IsDBNullAsync(5, cancellationToken) ? 0 : await reader.GetFieldValueAsync(5, cancellationToken), + await reader.IsDBNullAsync(6, cancellationToken) ? (byte?)0 : await reader.GetFieldValueAsync(6, cancellationToken), + await reader.IsDBNullAsync(7, cancellationToken) ? (byte?)0 : await reader.GetFieldValueAsync(7, cancellationToken), + await reader.IsDBNullAsync(7, cancellationToken) ? "text" : await reader.GetFieldValueAsync(4, cancellationToken)); + } + #endregion #region Methods @@ -138,7 +160,7 @@ public IEnumerable GetFields(IDbConnection connection, }; // Iterate and extract - using (var reader = connection.ExecuteReader(commandText, param, transaction: transaction)) + using (var reader = (DbDataReader)connection.ExecuteReader(commandText, param, transaction: transaction)) { var dbFields = new List(); @@ -159,10 +181,12 @@ public IEnumerable GetFields(IDbConnection connection, /// The instance of the connection object. /// The name of the target table. /// The transaction object that is currently in used. + /// The object to be used during the asynchronous operation. /// A list of of the target table. public async Task> GetFieldsAsync(IDbConnection connection, string tableName, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { // Variables var commandText = GetCommandText(); @@ -174,14 +198,15 @@ public async Task> GetFieldsAsync(IDbConnection connection, }; // Iterate and extract - using (var reader = await connection.ExecuteReaderAsync(commandText, param, transaction: transaction)) + using (var reader = (DbDataReader)await connection.ExecuteReaderAsync(commandText, param, + transaction: transaction, cancellationToken: cancellationToken)) { var dbFields = new List(); // Iterate the list of the fields - while (reader.Read()) + while (await reader.ReadAsync(cancellationToken)) { - dbFields.Add(ReaderToDbField(reader)); + dbFields.Add(await ReaderToDbFieldAsync(reader, cancellationToken)); } // Return the list of fields @@ -202,7 +227,8 @@ public async Task> GetFieldsAsync(IDbConnection connection, public object GetScopeIdentity(IDbConnection connection, IDbTransaction transaction = null) { - return connection.ExecuteScalar("SELECT COALESCE(SCOPE_IDENTITY(), @@IDENTITY);"); + return connection.ExecuteScalar("SELECT COALESCE(SCOPE_IDENTITY(), @@IDENTITY);", + transaction: transaction); } /// @@ -210,11 +236,15 @@ public object GetScopeIdentity(IDbConnection connection, /// /// The instance of the connection object. /// The transaction object that is currently in used. + /// The object to be used during the asynchronous operation. /// The newly generated identity from the database. public async Task GetScopeIdentityAsync(IDbConnection connection, - IDbTransaction transaction = null) + IDbTransaction transaction = null, + CancellationToken cancellationToken = default) { - return await connection.ExecuteScalarAsync("SELECT COALESCE(SCOPE_IDENTITY(), @@IDENTITY);"); + return await connection.ExecuteScalarAsync("SELECT COALESCE(SCOPE_IDENTITY(), @@IDENTITY);", + transaction: transaction, + cancellationToken: cancellationToken); } #endregion