diff --git a/RepoDb.Core/RepoDb/Extensions/DbConnectionExtension.cs b/RepoDb.Core/RepoDb/Extensions/DbConnectionExtension.cs
index f01579644..1f61da4cb 100644
--- a/RepoDb.Core/RepoDb/Extensions/DbConnectionExtension.cs
+++ b/RepoDb.Core/RepoDb/Extensions/DbConnectionExtension.cs
@@ -86,13 +86,12 @@ public static IDbConnection EnsureOpen(this IDbConnection connection)
/// Ensures the connection object is open in an asynchronous way.
///
/// The connection to be opened.
- /// A to observe while waiting for the task to complete.
/// The instance of the current connection object.
- public static async Task EnsureOpenAsync(this IDbConnection connection, CancellationToken cancellationToken = default)
+ public static async Task EnsureOpenAsync(this IDbConnection connection)
{
if (connection.State != ConnectionState.Open)
{
- await ((DbConnection)connection).OpenAsync(cancellationToken);
+ await ((DbConnection)connection).OpenAsync();
}
return connection;
}
@@ -237,6 +236,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.
///
@@ -248,7 +248,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 = null)
{
return ExecuteQueryAsyncInternal(connection: connection,
commandText: commandText,
@@ -259,6 +260,7 @@ public static Task> ExecuteQueryAsync(this IDbConnection co
commandTimeout: commandTimeout,
transaction: transaction,
cache: cache,
+ cancellationToken: cancellationToken,
tableName: null,
skipCommandArrayParametersCheck: false);
}
@@ -275,9 +277,9 @@ public static Task> ExecuteQueryAsync(this IDbConnection co
///
///
///
+ ///
///
///
- /// A to observe while waiting for the task to complete.
///
internal static async Task> ExecuteQueryAsyncInternal(this IDbConnection connection,
string commandText,
@@ -288,9 +290,9 @@ internal static async Task> ExecuteQueryAsyncInternal(this
int? commandTimeout = null,
IDbTransaction transaction = null,
ICache cache = null,
+ CancellationToken? cancellationToken = null,
string tableName = null,
- bool skipCommandArrayParametersCheck = true,
- CancellationToken cancellationToken = default)
+ bool skipCommandArrayParametersCheck = true)
{
// Get Cache
if (cacheKey != null)
@@ -304,7 +306,7 @@ internal static async Task> ExecuteQueryAsyncInternal(this
// DB Fields
var dbFields = !string.IsNullOrWhiteSpace(tableName) ?
- await DbFieldCache.GetAsync(connection, tableName, transaction, false, cancellationToken) : null;
+ await DbFieldCache.GetAsync(connection, tableName, transaction, false) : null;
// Execute the actual method
using (var command = await CreateDbCommandForExecutionAsync(connection: connection,
@@ -315,10 +317,9 @@ internal static async Task> ExecuteQueryAsyncInternal(this
transaction: transaction,
entityType: null,
dbFields: dbFields,
- skipCommandArrayParametersCheck: skipCommandArrayParametersCheck,
- cancellationToken: cancellationToken))
+ skipCommandArrayParametersCheck: skipCommandArrayParametersCheck))
{
- using (var reader = await command.ExecuteReaderAsync(cancellationToken))
+ using (var reader = cancellationToken.HasValue ? await command.ExecuteReaderAsync(cancellationToken.Value) : await command.ExecuteReaderAsync())
{
var result = (IEnumerable)DataReader.ToEnumerable(reader, dbFields, connection.GetDbSetting()).AsList();
@@ -611,6 +612,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.
///
@@ -622,6 +624,7 @@ public static Task> ExecuteQueryAsync(this IDbConn
int? cacheItemExpiration = Constant.DefaultCacheItemExpirationInMinutes,
int? commandTimeout = null,
IDbTransaction transaction = null,
+ CancellationToken? cancellationToken = null,
ICache cache = null)
{
return ExecuteQueryAsyncInternal(connection: connection,
@@ -632,6 +635,7 @@ public static Task> ExecuteQueryAsync(this IDbConn
cacheItemExpiration: cacheItemExpiration,
commandTimeout: commandTimeout,
transaction: transaction,
+ cancellationToken: cancellationToken,
cache: cache,
tableName: ClassMappedNameCache.Get(),
skipCommandArrayParametersCheck: false);
@@ -649,10 +653,10 @@ public static Task> ExecuteQueryAsync(this IDbConn
///
///
///
+ ///
///
///
///
- /// A to observe while waiting for the task to complete.
///
internal static Task> ExecuteQueryAsyncInternal(this IDbConnection connection,
string commandText,
@@ -662,10 +666,10 @@ internal static Task> ExecuteQueryAsyncInternal(th
int? cacheItemExpiration = Constant.DefaultCacheItemExpirationInMinutes,
int? commandTimeout = null,
IDbTransaction transaction = null,
+ CancellationToken? cancellationToken = null,
ICache cache = null,
string tableName = null,
- bool skipCommandArrayParametersCheck = true,
- CancellationToken cancellationToken = default)
+ bool skipCommandArrayParametersCheck = true)
{
// Get Cache
if (cacheKey != null)
@@ -691,10 +695,10 @@ internal static Task> ExecuteQueryAsyncInternal(th
cacheItemExpiration: cacheItemExpiration,
commandTimeout: commandTimeout,
transaction: transaction,
+ cancellationToken: cancellationToken,
cache: cache,
tableName: tableName,
- skipCommandArrayParametersCheck: skipCommandArrayParametersCheck,
- cancellationToken: cancellationToken);
+ skipCommandArrayParametersCheck: skipCommandArrayParametersCheck);
}
else
{
@@ -706,10 +710,10 @@ internal static Task> ExecuteQueryAsyncInternal(th
cacheItemExpiration: cacheItemExpiration,
commandTimeout: commandTimeout,
transaction: transaction,
+ cancellationToken: cancellationToken,
cache: cache,
tableName: tableName,
- skipCommandArrayParametersCheck: skipCommandArrayParametersCheck,
- cancellationToken: cancellationToken);
+ skipCommandArrayParametersCheck: skipCommandArrayParametersCheck);
}
}
@@ -725,10 +729,10 @@ internal static Task> ExecuteQueryAsyncInternal(th
///
///
///
+ ///
///
///
///
- /// A to observe while waiting for the task to complete.
///
private static async Task> ExecuteQueryAsyncInternalForDictionaryStringObject(this IDbConnection connection,
string commandText,
@@ -738,10 +742,10 @@ private static async Task> ExecuteQueryAsyncInternalForDict
int? cacheItemExpiration = Constant.DefaultCacheItemExpirationInMinutes,
int? commandTimeout = null,
IDbTransaction transaction = null,
+ CancellationToken? cancellationToken = null,
ICache cache = null,
string tableName = null,
- bool skipCommandArrayParametersCheck = true,
- CancellationToken cancellationToken = default)
+ bool skipCommandArrayParametersCheck = true)
{
// Get Cache
if (cacheKey != null)
@@ -762,10 +766,10 @@ private static async Task> ExecuteQueryAsyncInternalForDict
cacheItemExpiration: null,
commandTimeout: commandTimeout,
transaction: transaction,
+ cancellationToken: cancellationToken,
cache: null,
tableName: tableName,
- skipCommandArrayParametersCheck: skipCommandArrayParametersCheck,
- cancellationToken: cancellationToken)).OfTargetType();
+ skipCommandArrayParametersCheck: skipCommandArrayParametersCheck)).OfTargetType();
// Set Cache
if (cacheKey != null)
@@ -789,10 +793,10 @@ private static async Task> ExecuteQueryAsyncInternalForDict
///
///
///
+ ///
///
///
///
- /// A to observe while waiting for the task to complete.
///
private static async Task> ExecuteQueryAsyncInternalForType(this IDbConnection connection,
string commandText,
@@ -802,10 +806,10 @@ private static async Task> ExecuteQueryAsyncInternalForType
int? cacheItemExpiration = Constant.DefaultCacheItemExpirationInMinutes,
int? commandTimeout = null,
IDbTransaction transaction = null,
+ CancellationToken? cancellationToken = null,
ICache cache = null,
string tableName = null,
- bool skipCommandArrayParametersCheck = true,
- CancellationToken cancellationToken = default)
+ bool skipCommandArrayParametersCheck = true)
{
// Get Cache
if (cacheKey != null)
@@ -819,7 +823,7 @@ private static async Task> ExecuteQueryAsyncInternalForType
// DB Fields
var dbFields = !string.IsNullOrWhiteSpace(tableName) ?
- await DbFieldCache.GetAsync(connection, tableName, transaction, false, cancellationToken) : null;
+ await DbFieldCache.GetAsync(connection, tableName, transaction, false) : null;
// Execute the actual method
using (var command = await CreateDbCommandForExecutionAsync(connection: connection,
@@ -830,10 +834,9 @@ private static async Task> ExecuteQueryAsyncInternalForType
transaction: transaction,
entityType: typeof(TResult),
dbFields: dbFields,
- skipCommandArrayParametersCheck: skipCommandArrayParametersCheck,
- cancellationToken: cancellationToken))
+ skipCommandArrayParametersCheck: skipCommandArrayParametersCheck))
{
- using (var reader = await command.ExecuteReaderAsync(cancellationToken))
+ using (var reader = cancellationToken.HasValue ? await command.ExecuteReaderAsync(cancellationToken.Value) : await command.ExecuteReaderAsync())
{
var result = (IEnumerable)DataReader.ToEnumerable(reader, dbFields,
connection.GetDbSetting()).AsList();
@@ -901,13 +904,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 = null)
{
// Call
var reader = await ExecuteReaderAsyncInternal(connection: connection,
@@ -916,6 +921,7 @@ public static async Task ExecuteQueryMultipleAsync(this
commandType: commandType,
commandTimeout: commandTimeout,
transaction: transaction,
+ cancellationToken: cancellationToken,
entityType: null,
dbFields: null,
skipCommandArrayParametersCheck: false);
@@ -1032,13 +1038,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 = null)
{
return ExecuteReaderAsyncInternal(connection: connection,
commandText: commandText,
@@ -1046,6 +1054,7 @@ public static Task ExecuteReaderAsync(this IDbConnection connection
commandType: commandType,
commandTimeout: commandTimeout,
transaction: transaction,
+ cancellationToken: cancellationToken,
entityType: null,
dbFields: null,
skipCommandArrayParametersCheck: false);
@@ -1060,6 +1069,7 @@ public static Task ExecuteReaderAsync(this IDbConnection connection
///
///
///
+ ///
///
///
///
@@ -1070,6 +1080,7 @@ internal static async Task ExecuteReaderAsyncInternal(this IDbConne
CommandType? commandType,
int? commandTimeout,
IDbTransaction transaction,
+ CancellationToken? cancellationToken,
Type entityType,
IEnumerable dbFields,
bool skipCommandArrayParametersCheck)
@@ -1090,7 +1101,7 @@ internal static async Task ExecuteReaderAsyncInternal(this IDbConne
// Ensure the DbCommand disposal
try
{
- return await command.ExecuteReaderAsync();
+ return cancellationToken.HasValue ? await command.ExecuteReaderAsync(cancellationToken.Value) : await command.ExecuteReaderAsync();
}
catch
{
@@ -1196,13 +1207,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 = null)
{
return ExecuteNonQueryAsyncInternal(connection: connection,
commandText: commandText,
@@ -1210,6 +1223,7 @@ public static Task ExecuteNonQueryAsync(this IDbConnection connection,
commandType: commandType,
commandTimeout: commandTimeout,
transaction: transaction,
+ cancellationToken: cancellationToken,
entityType: null,
dbFields: null,
skipCommandArrayParametersCheck: false);
@@ -1224,6 +1238,7 @@ public static Task ExecuteNonQueryAsync(this IDbConnection connection,
///
///
///
+ ///
///
///
///
@@ -1234,6 +1249,7 @@ internal static async Task ExecuteNonQueryAsyncInternal(this IDbConnection
CommandType? commandType,
int? commandTimeout,
IDbTransaction transaction,
+ CancellationToken? cancellationToken,
Type entityType,
IEnumerable dbFields,
bool skipCommandArrayParametersCheck)
@@ -1248,7 +1264,7 @@ internal static async Task ExecuteNonQueryAsyncInternal(this IDbConnection
dbFields: dbFields,
skipCommandArrayParametersCheck: skipCommandArrayParametersCheck))
{
- return await command.ExecuteNonQueryAsync();
+ return cancellationToken.HasValue ? await command.ExecuteNonQueryAsync(cancellationToken.Value) : await command.ExecuteNonQueryAsync();
}
}
@@ -1342,13 +1358,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