diff --git a/src/InterpolatedSql.Dapper/IDapperSqlBuilderExtensions.cs b/src/InterpolatedSql.Dapper/IDapperSqlBuilderExtensions.cs index 55f63f1..6ffe0f4 100644 --- a/src/InterpolatedSql.Dapper/IDapperSqlBuilderExtensions.cs +++ b/src/InterpolatedSql.Dapper/IDapperSqlBuilderExtensions.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Data; +using System.Threading; using System.Threading.Tasks; using Dapper; using InterpolatedSql.Dapper.SqlBuilders; @@ -8,7 +9,7 @@ namespace InterpolatedSql.Dapper { /// - /// IDapperSqlCommand are "commands ready to run" - this is where we extend those commands with Dapper facades + /// IDapperSqlBuilder are "statements ready to run" - this is where we extend the builders with Dapper facades /// is the most generic builder - and is always ready to run. /// is a builder with some helpers to build SELECT queries - and is always ready to run. /// is a step-by-step fluent builder - it is ready to run only in some stages of the builder @@ -16,7 +17,7 @@ namespace InterpolatedSql.Dapper public static partial class IDapperSqlBuilderExtensions { - #region Dapper (IDapperSqlCommand.Execute()) + #region Dapper (IDapperSqlBuilder.Execute()) /// /// Executes the query (using Dapper), returning the number of rows affected. /// @@ -29,15 +30,15 @@ public static int Execute(this IDapperSqlBuilder builder, IDbTransaction? transa /// /// Executes the query (using Dapper), returning the number of rows affected. /// - public static Task ExecuteAsync(this IDapperSqlBuilder builder, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null) + public static Task ExecuteAsync(this IDapperSqlBuilder builder, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default) { var command = builder.Build(); - return command.DbConnection.ExecuteAsync(sql: command.Sql, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType); + return command.DbConnection.ExecuteAsync(new CommandDefinition(commandText: command.Sql, parameters: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, cancellationToken: cancellationToken)); } #endregion - #region Dapper (IDapperSqlCommand.ExecuteScalar()) + #region Dapper (IDapperSqlBuilder.ExecuteScalar()) /// /// Executes the query (using Dapper), returning the first cell returned, as object. /// @@ -59,24 +60,24 @@ public static T ExecuteScalar(this IDapperSqlBuilder builder, IDbTransaction? /// /// Executes the query (using Dapper), returning the first cell returned, as T. /// - public static Task ExecuteScalarAsync(this IDapperSqlBuilder builder, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null) + public static Task ExecuteScalarAsync(this IDapperSqlBuilder builder, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default) { var command = builder.Build(); - return command.DbConnection.ExecuteScalarAsync(sql: command.Sql, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType); + return command.DbConnection.ExecuteScalarAsync(new CommandDefinition(commandText: command.Sql, parameters: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, cancellationToken: cancellationToken)); } /// /// Executes the query (using Dapper), returning the first cell returned, as object. /// - public static Task ExecuteScalarAsync(this IDapperSqlBuilder builder, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null) + public static Task ExecuteScalarAsync(this IDapperSqlBuilder builder, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default) { var command = builder.Build(); - return command.DbConnection.ExecuteScalarAsync(sql: command.Sql, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType); + return command.DbConnection.ExecuteScalarAsync(new CommandDefinition(commandText: command.Sql, parameters: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, cancellationToken: cancellationToken)); } #endregion - #region Dapper (IDapperSqlCommand.QueryMultiple()) + #region Dapper (IDapperSqlBuilder.QueryMultiple()) /// /// Executes the query (using Dapper), returning multiple result sets, and access each in turn. /// @@ -90,16 +91,16 @@ public static SqlMapper.GridReader QueryMultiple(this IDapperSqlBuilder builder, /// /// Executes the query (using Dapper), returning multiple result sets, and access each in turn. /// - public static Task QueryMultipleAsync(this IDapperSqlBuilder builder, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null) + public static Task QueryMultipleAsync(this IDapperSqlBuilder builder, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default) { var command = builder.Build(); // DynamicParameters because QueryMultiple with Stored Procedures doesn't work with Dictionary - see https://github.com/DapperLib/Dapper/issues/1580#issuecomment-889813797 - return command.DbConnection.QueryMultipleAsync(sql: command.Sql, param: ParametersDictionary.LoadFrom(command).DynamicParameters, transaction: transaction, commandTimeout: commandTimeout, commandType: commandType); + return command.DbConnection.QueryMultipleAsync(new CommandDefinition(commandText: command.Sql, parameters: ParametersDictionary.LoadFrom(command).DynamicParameters, transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, cancellationToken: cancellationToken)); } #endregion - #region Dapper (IDapperSqlCommand.Query) + #region Dapper (IDapperSqlBuilder.Query) /// /// Executes the query (using Dapper), returning the data typed as T. /// @@ -146,7 +147,7 @@ public static T QuerySingleOrDefault(this IDapperSqlBuilder builder, IDbTrans } #endregion - #region Dapper (IDapperSqlCommand.Query() dynamic) + #region Dapper (IDapperSqlBuilder.Query() dynamic) /// /// Executes the query (using Dapper), returning the data typed as dynamic objects. /// @@ -193,7 +194,7 @@ public static dynamic QuerySingleOrDefault(this IDapperSqlBuilder builder, IDbTr } #endregion - #region Dapper (IDapperSqlCommand.Query()) + #region Dapper (IDapperSqlBuilder.Query()) /// /// Executes the query (using Dapper), returning the data typed as type. /// @@ -240,142 +241,148 @@ public static object QuerySingleOrDefault(this IDapperSqlBuilder builder, Type t } #endregion - #region Dapper (IDapperSqlCommand.QueryAsync) + #region Dapper (IDapperSqlBuilder.QueryAsync) /// /// Executes the query (using Dapper), returning the data typed as T. /// - public static Task> QueryAsync(this IDapperSqlBuilder builder, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null) + public static Task> QueryAsync(this IDapperSqlBuilder builder, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default) { var command = builder.Build(); - return command.DbConnection.QueryAsync(sql: command.Sql, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType); + return command.DbConnection.QueryAsync(new CommandDefinition(commandText: command.Sql, parameters: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, cancellationToken: cancellationToken)); } /// /// Executes the query (using Dapper), returning the data typed as T. /// - public static Task QueryFirstAsync(this IDapperSqlBuilder builder, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null) + public static Task QueryFirstAsync(this IDapperSqlBuilder builder, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default) { var command = builder.Build(); - return command.DbConnection.QueryFirstAsync(sql: command.Sql, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType); + return command.DbConnection.QueryFirstAsync(new CommandDefinition(commandText: command.Sql, parameters: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, cancellationToken: cancellationToken)); } + /// /// Executes the query (using Dapper), returning the data typed as T. /// - public static Task QueryFirstOrDefaultAsync(this IDapperSqlBuilder builder, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null) + public static Task QueryFirstOrDefaultAsync(this IDapperSqlBuilder builder, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default) { var command = builder.Build(); - return command.DbConnection.QueryFirstOrDefaultAsync(sql: command.Sql, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType); + return command.DbConnection.QueryFirstOrDefaultAsync(new CommandDefinition(commandText: command.Sql, parameters: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, cancellationToken: cancellationToken)); } + /// /// Executes the query (using Dapper), returning the data typed as T. /// - public static Task QuerySingleAsync(this IDapperSqlBuilder builder, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null) + public static Task QuerySingleAsync(this IDapperSqlBuilder builder, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default) { var command = builder.Build(); - return command.DbConnection.QuerySingleAsync(sql: command.Sql, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType); + return command.DbConnection.QuerySingleAsync(new CommandDefinition(commandText: command.Sql, parameters: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, cancellationToken: cancellationToken)); } + /// /// Executes the query (using Dapper), returning the data typed as T. /// - public static Task QuerySingleOrDefaultAsync(this IDapperSqlBuilder builder, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null) + public static Task QuerySingleOrDefaultAsync(this IDapperSqlBuilder builder, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default) { var command = builder.Build(); - return command.DbConnection.QuerySingleOrDefaultAsync(sql: command.Sql, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType); + return command.DbConnection.QuerySingleOrDefaultAsync(new CommandDefinition(commandText: command.Sql, parameters: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, cancellationToken: cancellationToken)); } #endregion - #region Dapper (IDapperSqlCommand.QueryAsync() dynamic) + #region Dapper (IDapperSqlBuilder.QueryAsync() dynamic) /// /// Executes the query (using Dapper), returning the data typed as dynamic objects. /// - public static Task> QueryAsync(this IDapperSqlBuilder builder, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null) + public static Task> QueryAsync(this IDapperSqlBuilder builder, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default) { var command = builder.Build(); - return command.DbConnection.QueryAsync(sql: command.Sql, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType); + return command.DbConnection.QueryAsync(new CommandDefinition(commandText: command.Sql, parameters: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, cancellationToken: cancellationToken)); } /// /// Executes the query (using Dapper), returning the data typed as dynamic objects. /// - public static Task QueryFirstAsync(this IDapperSqlBuilder builder, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null) + public static Task QueryFirstAsync(this IDapperSqlBuilder builder, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default) { var command = builder.Build(); - return command.DbConnection.QueryFirstAsync(sql: command.Sql, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType); + return command.DbConnection.QueryFirstAsync(new CommandDefinition(commandText: command.Sql, parameters: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, cancellationToken: cancellationToken)); } /// /// Executes the query (using Dapper), returning the data typed as dynamic objects. /// - public static Task QueryFirstOrDefaultAsync(this IDapperSqlBuilder builder, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null) + public static Task QueryFirstOrDefaultAsync(this IDapperSqlBuilder builder, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default) { var command = builder.Build(); - return command.DbConnection.QueryFirstOrDefaultAsync(sql: command.Sql, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType); + return command.DbConnection.QueryFirstOrDefaultAsync(new CommandDefinition(commandText: command.Sql, parameters: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, cancellationToken: cancellationToken)); } /// /// Executes the query (using Dapper), returning the data typed as dynamic objects. /// - public static Task QuerySingleAsync(this IDapperSqlBuilder builder, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null) + public static Task QuerySingleAsync(this IDapperSqlBuilder builder, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default) { var command = builder.Build(); - return command.DbConnection.QuerySingleAsync(sql: command.Sql, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType); + return command.DbConnection.QuerySingleAsync(new CommandDefinition(commandText: command.Sql, parameters: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, cancellationToken: cancellationToken)); } /// /// Executes the query (using Dapper), returning the data typed as dynamic objects. /// - public static Task QuerySingleOrDefaultAsync(this IDapperSqlBuilder builder, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null) + public static Task QuerySingleOrDefaultAsync(this IDapperSqlBuilder builder, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default) { var command = builder.Build(); - return command.DbConnection.QuerySingleOrDefaultAsync(sql: command.Sql, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType); + return command.DbConnection.QuerySingleOrDefaultAsync(new CommandDefinition(commandText: command.Sql, parameters: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, cancellationToken: cancellationToken)); } #endregion - #region Dapper (IDapperSqlCommand.QueryAsync) + #region Dapper (IDapperSqlBuilder.QueryAsync) /// /// Executes the query (using Dapper), returning the data typed as type. /// - public static Task> QueryAsync(this IDapperSqlBuilder builder, Type type, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null) + public static Task> QueryAsync(this IDapperSqlBuilder builder, Type type, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default) { var command = builder.Build(); - return command.DbConnection.QueryAsync(type: type, sql: command.Sql, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType); + return command.DbConnection.QueryAsync(type: type, command: new CommandDefinition(commandText: command.Sql, parameters: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, cancellationToken: cancellationToken)); } /// /// Executes the query (using Dapper), returning the data typed as type. /// - public static Task QueryFirstAsync(this IDapperSqlBuilder builder, Type type, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null) + public static Task QueryFirstAsync(this IDapperSqlBuilder builder, Type type, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default) { var command = builder.Build(); - return command.DbConnection.QueryFirstAsync(type: type, sql: command.Sql, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType); + return command.DbConnection.QueryFirstAsync(type: type, command: new CommandDefinition(commandText: command.Sql, parameters: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, cancellationToken: cancellationToken)); } + /// /// Executes the query (using Dapper), returning the data typed as type. /// - public static Task QueryFirstOrDefaultAsync(this IDapperSqlBuilder builder, Type type, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null) + public static Task QueryFirstOrDefaultAsync(this IDapperSqlBuilder builder, Type type, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default) { var command = builder.Build(); - return command.DbConnection.QueryFirstOrDefaultAsync(type: type, sql: command.Sql, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType); + return command.DbConnection.QueryFirstOrDefaultAsync(type: type, command: new CommandDefinition(commandText: command.Sql, parameters: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, cancellationToken: cancellationToken)); } + /// /// Executes the query (using Dapper), returning the data typed as type. /// - public static Task QuerySingleAsync(this IDapperSqlBuilder builder, Type type, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null) + public static Task QuerySingleAsync(this IDapperSqlBuilder builder, Type type, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default) { var command = builder.Build(); - return command.DbConnection.QuerySingleAsync(type: type, sql: command.Sql, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType); + return command.DbConnection.QuerySingleAsync(type: type, command: new CommandDefinition(commandText: command.Sql, parameters: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, cancellationToken: cancellationToken)); } + /// /// Executes the query (using Dapper), returning the data typed as type. /// - public static Task QuerySingleOrDefaultAsync(this IDapperSqlBuilder builder, Type type, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null) + public static Task QuerySingleOrDefaultAsync(this IDapperSqlBuilder builder, Type type, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default) { var command = builder.Build(); - return command.DbConnection.QuerySingleOrDefaultAsync(type: type, sql: command.Sql, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType); + return command.DbConnection.QuerySingleOrDefaultAsync(type: type, new CommandDefinition(commandText: command.Sql, parameters: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, cancellationToken: cancellationToken)); } #endregion - #region Dapper (IDapperSqlCommand.ExecuteReader()) + #region Dapper (IDapperSqlBuilder.ExecuteReader()) /// /// Executes the query (using Dapper), returning an System.Data.IDataReader /// @@ -388,10 +395,10 @@ public static IDataReader ExecuteReader(this IDapperSqlBuilder builder, IDbTrans /// /// Executes the query (using Dapper), returning an System.Data.IDataReader /// - public static Task ExecuteReaderAsync(this IDapperSqlBuilder builder, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null) + public static Task ExecuteReaderAsync(this IDapperSqlBuilder builder, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default) { var command = builder.Build(); - return command.DbConnection.ExecuteReaderAsync(sql: command.Sql, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType); + return command.DbConnection.ExecuteReaderAsync(new CommandDefinition(commandText: command.Sql, parameters: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, cancellationToken: cancellationToken)); } #endregion @@ -403,6 +410,7 @@ public static Task ExecuteReaderAsync(this IDapperSqlBuilder builde /// The first type in the recordset. /// The second type in the recordset. /// The combined type to return. + /// IDapperSqlBuilder used to query the DbConnection. /// The function to map row types to the return type. /// The transaction to use for this query. /// Whether to buffer the results in memory. @@ -410,13 +418,12 @@ public static Task ExecuteReaderAsync(this IDapperSqlBuilder builde /// Number of seconds before command execution timeout. /// Is it a stored proc or a batch? /// An enumerable of . - public static IEnumerable Query(this IDapperSqlBuilder builder, Func map, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null) + public static IEnumerable Query(this IDapperSqlBuilder builder, Func map, IDbTransaction? transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null) { var command = builder.Build(); return command.DbConnection.Query(sql: command.Sql, map: map, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, buffered: buffered, splitOn: splitOn); } - /// /// Perform a multi-mapping query with 3 input types. /// This returns a single type, combined from the raw types via . @@ -425,6 +432,7 @@ public static IEnumerable Query(this IDapperS /// The second type in the recordset. /// The third type in the recordset. /// The combined type to return. + /// IDapperSqlBuilder used to query the DbConnection. /// The function to map row types to the return type. /// The transaction to use for this query. /// Whether to buffer the results in memory. @@ -432,7 +440,7 @@ public static IEnumerable Query(this IDapperS /// Number of seconds before command execution timeout. /// Is it a stored proc or a batch? /// An enumerable of . - public static IEnumerable Query(this IDapperSqlBuilder builder, Func map, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null) + public static IEnumerable Query(this IDapperSqlBuilder builder, Func map, IDbTransaction? transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null) { var command = builder.Build(); return command.DbConnection.Query(sql: command.Sql, map: map, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, buffered: buffered, splitOn: splitOn); @@ -447,6 +455,7 @@ public static IEnumerable Query(this /// The third type in the recordset. /// The fourth type in the recordset. /// The combined type to return. + /// IDapperSqlBuilder used to query the DbConnection. /// The function to map row types to the return type. /// The transaction to use for this query. /// Whether to buffer the results in memory. @@ -454,7 +463,7 @@ public static IEnumerable Query(this /// Number of seconds before command execution timeout. /// Is it a stored proc or a batch? /// An enumerable of . - public static IEnumerable Query(this IDapperSqlBuilder builder, Func map, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null) + public static IEnumerable Query(this IDapperSqlBuilder builder, Func map, IDbTransaction? transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null) { var command = builder.Build(); return command.DbConnection.Query(sql: command.Sql, map: map, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, buffered: buffered, splitOn: splitOn); @@ -470,6 +479,7 @@ public static IEnumerable QueryThe fourth type in the recordset. /// The fifth type in the recordset. /// The combined type to return. + /// IDapperSqlBuilder used to query the DbConnection. /// The function to map row types to the return type. /// The transaction to use for this query. /// Whether to buffer the results in memory. @@ -477,7 +487,7 @@ public static IEnumerable QueryNumber of seconds before command execution timeout. /// Is it a stored proc or a batch? /// An enumerable of . - public static IEnumerable Query(this IDapperSqlBuilder builder, Func map, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null) + public static IEnumerable Query(this IDapperSqlBuilder builder, Func map, IDbTransaction? transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null) { var command = builder.Build(); return command.DbConnection.Query(sql: command.Sql, map: map, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, buffered: buffered, splitOn: splitOn); @@ -494,6 +504,7 @@ public static IEnumerable QueryThe fifth type in the recordset. /// The sixth type in the recordset. /// The combined type to return. + /// IDapperSqlBuilder used to query the DbConnection. /// The function to map row types to the return type. /// The transaction to use for this query. /// Whether to buffer the results in memory. @@ -501,7 +512,7 @@ public static IEnumerable QueryNumber of seconds before command execution timeout. /// Is it a stored proc or a batch? /// An enumerable of . - public static IEnumerable Query(this IDapperSqlBuilder builder, Func map, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null) + public static IEnumerable Query(this IDapperSqlBuilder builder, Func map, IDbTransaction? transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null) { var command = builder.Build(); return command.DbConnection.Query(sql: command.Sql, map: map, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, buffered: buffered, splitOn: splitOn); @@ -519,6 +530,7 @@ public static IEnumerable QueryThe sixth type in the recordset. /// The seventh type in the recordset. /// The combined type to return. + /// IDapperSqlBuilder used to query the DbConnection. /// The function to map row types to the return type. /// The transaction to use for this query. /// Whether to buffer the results in memory. @@ -526,7 +538,7 @@ public static IEnumerable QueryNumber of seconds before command execution timeout. /// Is it a stored proc or a batch? /// An enumerable of . - public static IEnumerable Query(this IDapperSqlBuilder builder, Func map, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null) + public static IEnumerable Query(this IDapperSqlBuilder builder, Func map, IDbTransaction? transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null) { var command = builder.Build(); return command.DbConnection.Query(sql: command.Sql, map: map, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, buffered: buffered, splitOn: splitOn); @@ -537,6 +549,7 @@ public static IEnumerable Query. /// /// The combined type to return. + /// IDapperSqlBuilder used to query the DbConnection. /// Array of types in the recordset. /// The function to map row types to the return type. /// The transaction to use for this query. @@ -545,7 +558,7 @@ public static IEnumerable QueryNumber of seconds before command execution timeout. /// Is it a stored proc or a batch? /// An enumerable of . - public static IEnumerable Query(this IDapperSqlBuilder builder, Type[] types, Func map, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null) + public static IEnumerable Query(this IDapperSqlBuilder builder, Type[] types, Func map, IDbTransaction? transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null) { var command = builder.Build(); return command.DbConnection.Query(sql: command.Sql, types, map: map, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, buffered: buffered, splitOn: splitOn); @@ -561,17 +574,19 @@ public static IEnumerable Query(this IDapperSqlBuilder builder /// The first type in the recordset. /// The second type in the recordset. /// The combined type to return. + /// IDapperSqlBuilder used to query the DbConnection. /// The function to map row types to the return type. /// The transaction to use for this query. /// Whether to buffer the results in memory. /// The field we should split and read the second object from (default: "Id"). /// Number of seconds before command execution timeout. /// Is it a stored proc or a batch? + /// The cancellation token for this command. /// An enumerable of . - public static Task> QueryAsync(this IDapperSqlBuilder builder, Func map, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null) + public static Task> QueryAsync(this IDapperSqlBuilder builder, Func map, IDbTransaction? transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default) { var command = builder.Build(); - return command.DbConnection.QueryAsync(sql: command.Sql, map: map, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, buffered: buffered, splitOn: splitOn); + return command.DbConnection.QueryAsync(map: map, splitOn: splitOn, command: new CommandDefinition(commandText: command.Sql, parameters: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, flags: buffered ? CommandFlags.Buffered : CommandFlags.None, cancellationToken: cancellationToken)); } @@ -583,17 +598,19 @@ public static Task> QueryAsync(th /// The second type in the recordset. /// The third type in the recordset. /// The combined type to return. + /// IDapperSqlBuilder used to query the DbConnection. /// The function to map row types to the return type. /// The transaction to use for this query. /// Whether to buffer the results in memory. /// The field we should split and read the second object from (default: "Id"). /// Number of seconds before command execution timeout. /// Is it a stored proc or a batch? + /// The cancellation token for this command. /// An enumerable of . - public static Task> QueryAsync(this IDapperSqlBuilder builder, Func map, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null) + public static Task> QueryAsync(this IDapperSqlBuilder builder, Func map, IDbTransaction? transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default) { var command = builder.Build(); - return command.DbConnection.QueryAsync(sql: command.Sql, map: map, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, buffered: buffered, splitOn: splitOn); + return command.DbConnection.QueryAsync(map: map, splitOn: splitOn, command: new CommandDefinition(commandText: command.Sql, parameters: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, flags: buffered ? CommandFlags.Buffered : CommandFlags.None, cancellationToken: cancellationToken)); } /// @@ -605,17 +622,19 @@ public static Task> QueryAsyncThe third type in the recordset. /// The fourth type in the recordset. /// The combined type to return. + /// IDapperSqlBuilder used to query the DbConnection. /// The function to map row types to the return type. /// The transaction to use for this query. /// Whether to buffer the results in memory. /// The field we should split and read the second object from (default: "Id"). /// Number of seconds before command execution timeout. /// Is it a stored proc or a batch? + /// The cancellation token for this command. /// An enumerable of . - public static Task> QueryAsync(this IDapperSqlBuilder builder, Func map, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null) + public static Task> QueryAsync(this IDapperSqlBuilder builder, Func map, IDbTransaction? transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default) { var command = builder.Build(); - return command.DbConnection.QueryAsync(sql: command.Sql, map: map, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, buffered: buffered, splitOn: splitOn); + return command.DbConnection.QueryAsync(map: map, splitOn: splitOn, command: new CommandDefinition(commandText: command.Sql, parameters: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, flags: buffered ? CommandFlags.Buffered : CommandFlags.None, cancellationToken: cancellationToken)); } /// @@ -628,17 +647,19 @@ public static Task> QueryAsyncThe fourth type in the recordset. /// The fifth type in the recordset. /// The combined type to return. + /// IDapperSqlBuilder used to query the DbConnection. /// The function to map row types to the return type. /// The transaction to use for this query. /// Whether to buffer the results in memory. /// The field we should split and read the second object from (default: "Id"). /// Number of seconds before command execution timeout. /// Is it a stored proc or a batch? + /// The cancellation token for this command. /// An enumerable of . - public static Task> QueryAsync(this IDapperSqlBuilder builder, Func map, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null) + public static Task> QueryAsync(this IDapperSqlBuilder builder, Func map, IDbTransaction? transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default) { var command = builder.Build(); - return command.DbConnection.QueryAsync(sql: command.Sql, map: map, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, buffered: buffered, splitOn: splitOn); + return command.DbConnection.QueryAsync(map: map, splitOn: splitOn, command: new CommandDefinition(commandText: command.Sql, parameters: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, flags: buffered ? CommandFlags.Buffered : CommandFlags.None, cancellationToken: cancellationToken)); } /// @@ -652,17 +673,19 @@ public static Task> QueryAsyncThe fifth type in the recordset. /// The sixth type in the recordset. /// The combined type to return. + /// IDapperSqlBuilder used to query the DbConnection. /// The function to map row types to the return type. /// The transaction to use for this query. /// Whether to buffer the results in memory. /// The field we should split and read the second object from (default: "Id"). /// Number of seconds before command execution timeout. /// Is it a stored proc or a batch? + /// The cancellation token for this command. /// An enumerable of . - public static Task> QueryAsync(this IDapperSqlBuilder builder, Func map, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null) + public static Task> QueryAsync(this IDapperSqlBuilder builder, Func map, IDbTransaction? transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default) { var command = builder.Build(); - return command.DbConnection.QueryAsync(sql: command.Sql, map: map, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, buffered: buffered, splitOn: splitOn); + return command.DbConnection.QueryAsync(map: map, splitOn: splitOn, command: new CommandDefinition(commandText: command.Sql, parameters: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, flags: buffered ? CommandFlags.Buffered : CommandFlags.None, cancellationToken: cancellationToken)); } /// @@ -677,17 +700,19 @@ public static Task> QueryAsyncThe sixth type in the recordset. /// The seventh type in the recordset. /// The combined type to return. + /// IDapperSqlBuilder used to query the DbConnection. /// The function to map row types to the return type. /// The transaction to use for this query. /// Whether to buffer the results in memory. /// The field we should split and read the second object from (default: "Id"). /// Number of seconds before command execution timeout. /// Is it a stored proc or a batch? + /// The cancellation token for this command. /// An enumerable of . - public static Task> QueryAsync(this IDapperSqlBuilder builder, Func map, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null) + public static Task> QueryAsync(this IDapperSqlBuilder builder, Func map, IDbTransaction? transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default) { var command = builder.Build(); - return command.DbConnection.QueryAsync(sql: command.Sql, map: map, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, buffered: buffered, splitOn: splitOn); + return command.DbConnection.QueryAsync(map: map, splitOn: splitOn, command: new CommandDefinition(commandText: command.Sql, parameters: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, flags: buffered ? CommandFlags.Buffered : CommandFlags.None, cancellationToken: cancellationToken)); } /// @@ -695,6 +720,7 @@ public static Task> QueryAsync. /// /// The combined type to return. + /// IDapperSqlBuilder used to query the DbConnection. /// Array of types in the recordset. /// The function to map row types to the return type. /// The transaction to use for this query. @@ -702,15 +728,15 @@ public static Task> QueryAsyncThe field we should split and read the second object from (default: "Id"). /// Number of seconds before command execution timeout. /// Is it a stored proc or a batch? + /// The cancellation token for this command. /// An enumerable of . - public static Task> QueryAsync(this IDapperSqlBuilder builder, Type[] types, Func map, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null) + public static Task> QueryAsync(this IDapperSqlBuilder builder, Type[] types, Func map, IDbTransaction? transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default) { var command = builder.Build(); - return command.DbConnection.QueryAsync(sql: command.Sql, types, map: map, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, buffered: buffered, splitOn: splitOn); + // return command.DbConnection.QueryAsync(command: new CommandDefinition(commandText: command.Sql, parameters: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, flags: buffered ? CommandFlags.Buffered : CommandFlags.None, cancellationToken: cancellationToken), types: types, map: map, splitOn: splitOn); + return command.DbConnection.QueryAsync(sql: command.Sql, types, map: map, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, buffered: buffered, splitOn: splitOn); } #endregion - - } } diff --git a/src/InterpolatedSql.Dapper/IDapperSqlCommandExtensions.cs b/src/InterpolatedSql.Dapper/IDapperSqlCommandExtensions.cs index 50d40c6..7fa0b8c 100644 --- a/src/InterpolatedSql.Dapper/IDapperSqlCommandExtensions.cs +++ b/src/InterpolatedSql.Dapper/IDapperSqlCommandExtensions.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Data; +using System.Threading; using System.Threading.Tasks; using Dapper; @@ -27,9 +28,9 @@ public static int Execute(this IDapperSqlCommand command, IDbTransaction? transa /// /// Executes the query (using Dapper), returning the number of rows affected. /// - public static Task ExecuteAsync(this IDapperSqlCommand command, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null) + public static Task ExecuteAsync(this IDapperSqlCommand command, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default) { - return command.DbConnection.ExecuteAsync(sql: command.Sql, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType); + return command.DbConnection.ExecuteAsync(new CommandDefinition(commandText: command.Sql, parameters: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, cancellationToken: cancellationToken)); } #endregion @@ -46,25 +47,25 @@ public static object ExecuteScalar(this IDapperSqlCommand command, IDbTransactio /// /// Executes the query (using Dapper), returning the first cell returned, as T. /// - public static T ExecuteScalar(this IDapperSqlCommand command, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null) + public static T ExecuteScalar(this IDapperSqlCommand command, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default) { - return command.DbConnection.ExecuteScalar(sql: command.Sql, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType); + return command.DbConnection.ExecuteScalar(new CommandDefinition(commandText: command.Sql, parameters: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, cancellationToken: cancellationToken)); } /// /// Executes the query (using Dapper), returning the first cell returned, as T. /// - public static Task ExecuteScalarAsync(this IDapperSqlCommand command, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null) + public static Task ExecuteScalarAsync(this IDapperSqlCommand command, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default) { - return command.DbConnection.ExecuteScalarAsync(sql: command.Sql, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType); + return command.DbConnection.ExecuteScalarAsync(new CommandDefinition(commandText: command.Sql, parameters: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, cancellationToken: cancellationToken)); } /// /// Executes the query (using Dapper), returning the first cell returned, as object. /// - public static Task ExecuteScalarAsync(this IDapperSqlCommand command, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null) + public static Task ExecuteScalarAsync(this IDapperSqlCommand command, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default) { - return command.DbConnection.ExecuteScalarAsync(sql: command.Sql, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType); + return command.DbConnection.ExecuteScalarAsync(new CommandDefinition(commandText: command.Sql, parameters: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, cancellationToken: cancellationToken)); } #endregion @@ -82,10 +83,10 @@ public static SqlMapper.GridReader QueryMultiple(this IDapperSqlCommand command, /// /// Executes the query (using Dapper), returning multiple result sets, and access each in turn. /// - public static Task QueryMultipleAsync(this IDapperSqlCommand command, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null) + public static Task QueryMultipleAsync(this IDapperSqlCommand command, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default) { // DynamicParameters because QueryMultiple with Stored Procedures doesn't work with Dictionary - see https://github.com/DapperLib/Dapper/issues/1580#issuecomment-889813797 - return command.DbConnection.QueryMultipleAsync(sql: command.Sql, param: ParametersDictionary.LoadFrom(command).DynamicParameters, transaction: transaction, commandTimeout: commandTimeout, commandType: commandType); + return command.DbConnection.QueryMultipleAsync(new CommandDefinition(commandText: command.Sql, parameters: ParametersDictionary.LoadFrom(command).DynamicParameters, transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, cancellationToken: cancellationToken)); } #endregion @@ -220,38 +221,41 @@ public static object QuerySingleOrDefault(this IDapperSqlCommand command, Type t /// /// Executes the query (using Dapper), returning the data typed as T. /// - public static Task> QueryAsync(this IDapperSqlCommand command, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null) + public static Task> QueryAsync(this IDapperSqlCommand command, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default) { - return command.DbConnection.QueryAsync(sql: command.Sql, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType); + return command.DbConnection.QueryAsync(new CommandDefinition(commandText: command.Sql, parameters: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, cancellationToken: cancellationToken)); } /// /// Executes the query (using Dapper), returning the data typed as T. /// - public static Task QueryFirstAsync(this IDapperSqlCommand command, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null) + public static Task QueryFirstAsync(this IDapperSqlCommand command, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default) { - return command.DbConnection.QueryFirstAsync(sql: command.Sql, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType); + return command.DbConnection.QueryFirstAsync(new CommandDefinition(commandText: command.Sql, parameters: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, cancellationToken: cancellationToken)); } + /// /// Executes the query (using Dapper), returning the data typed as T. /// - public static Task QueryFirstOrDefaultAsync(this IDapperSqlCommand command, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null) + public static Task QueryFirstOrDefaultAsync(this IDapperSqlCommand command, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default) { - return command.DbConnection.QueryFirstOrDefaultAsync(sql: command.Sql, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType); + return command.DbConnection.QueryFirstOrDefaultAsync(new CommandDefinition(commandText: command.Sql, parameters: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, cancellationToken: cancellationToken)); } + /// /// Executes the query (using Dapper), returning the data typed as T. /// - public static Task QuerySingleAsync(this IDapperSqlCommand command, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null) + public static Task QuerySingleAsync(this IDapperSqlCommand command, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default) { - return command.DbConnection.QuerySingleAsync(sql: command.Sql, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType); + return command.DbConnection.QuerySingleAsync(new CommandDefinition(commandText: command.Sql, parameters: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, cancellationToken: cancellationToken)); } + /// /// Executes the query (using Dapper), returning the data typed as T. /// - public static Task QuerySingleOrDefaultAsync(this IDapperSqlCommand command, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null) + public static Task QuerySingleOrDefaultAsync(this IDapperSqlCommand command, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default) { - return command.DbConnection.QuerySingleOrDefaultAsync(sql: command.Sql, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType); + return command.DbConnection.QuerySingleOrDefaultAsync(new CommandDefinition(commandText: command.Sql, parameters: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, cancellationToken: cancellationToken)); } #endregion @@ -259,41 +263,41 @@ public static Task QuerySingleOrDefaultAsync(this IDapperSqlCommand comman /// /// Executes the query (using Dapper), returning the data typed as dynamic objects. /// - public static Task> QueryAsync(this IDapperSqlCommand command, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null) + public static Task> QueryAsync(this IDapperSqlCommand command, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default) { - return command.DbConnection.QueryAsync(sql: command.Sql, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType); + return command.DbConnection.QueryAsync(new CommandDefinition(commandText: command.Sql, parameters: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, cancellationToken: cancellationToken)); } /// /// Executes the query (using Dapper), returning the data typed as dynamic objects. /// - public static Task QueryFirstAsync(this IDapperSqlCommand command, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null) + public static Task QueryFirstAsync(this IDapperSqlCommand command, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default) { - return command.DbConnection.QueryFirstAsync(sql: command.Sql, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType); + return command.DbConnection.QueryFirstAsync(new CommandDefinition(commandText: command.Sql, parameters: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, cancellationToken: cancellationToken)); } /// /// Executes the query (using Dapper), returning the data typed as dynamic objects. /// - public static Task QueryFirstOrDefaultAsync(this IDapperSqlCommand command, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null) + public static Task QueryFirstOrDefaultAsync(this IDapperSqlCommand command, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default) { - return command.DbConnection.QueryFirstOrDefaultAsync(sql: command.Sql, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType); + return command.DbConnection.QueryFirstOrDefaultAsync(new CommandDefinition(commandText: command.Sql, parameters: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, cancellationToken: cancellationToken)); } /// /// Executes the query (using Dapper), returning the data typed as dynamic objects. /// - public static Task QuerySingleAsync(this IDapperSqlCommand command, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null) + public static Task QuerySingleAsync(this IDapperSqlCommand command, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default) { - return command.DbConnection.QuerySingleAsync(sql: command.Sql, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType); + return command.DbConnection.QuerySingleAsync(new CommandDefinition(commandText: command.Sql, parameters: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, cancellationToken: cancellationToken)); } /// /// Executes the query (using Dapper), returning the data typed as dynamic objects. /// - public static Task QuerySingleOrDefaultAsync(this IDapperSqlCommand command, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null) + public static Task QuerySingleOrDefaultAsync(this IDapperSqlCommand command, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default) { - return command.DbConnection.QuerySingleOrDefaultAsync(sql: command.Sql, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType); + return command.DbConnection.QuerySingleOrDefaultAsync(new CommandDefinition(commandText: command.Sql, parameters: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, cancellationToken: cancellationToken)); } #endregion @@ -301,38 +305,41 @@ public static Task QuerySingleOrDefaultAsync(this IDapperSqlCommand com /// /// Executes the query (using Dapper), returning the data typed as type. /// - public static Task> QueryAsync(this IDapperSqlCommand command, Type type, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null) + public static Task> QueryAsync(this IDapperSqlCommand command, Type type, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default) { - return command.DbConnection.QueryAsync(type: type, sql: command.Sql, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType); + return command.DbConnection.QueryAsync(type: type, command: new CommandDefinition(commandText: command.Sql, parameters: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, cancellationToken: cancellationToken)); } /// /// Executes the query (using Dapper), returning the data typed as type. /// - public static Task QueryFirstAsync(this IDapperSqlCommand command, Type type, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null) + public static Task QueryFirstAsync(this IDapperSqlCommand command, Type type, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default) { - return command.DbConnection.QueryFirstAsync(type: type, sql: command.Sql, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType); + return command.DbConnection.QueryFirstAsync(type: type, command: new CommandDefinition(commandText: command.Sql, parameters: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, cancellationToken: cancellationToken)); } + /// /// Executes the query (using Dapper), returning the data typed as type. /// - public static Task QueryFirstOrDefaultAsync(this IDapperSqlCommand command, Type type, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null) + public static Task QueryFirstOrDefaultAsync(this IDapperSqlCommand command, Type type, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default) { - return command.DbConnection.QueryFirstOrDefaultAsync(type: type, sql: command.Sql, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType); + return command.DbConnection.QueryFirstOrDefaultAsync(type: type, command: new CommandDefinition(commandText: command.Sql, parameters: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, cancellationToken: cancellationToken)); } + /// /// Executes the query (using Dapper), returning the data typed as type. /// - public static Task QuerySingleAsync(this IDapperSqlCommand command, Type type, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null) + public static Task QuerySingleAsync(this IDapperSqlCommand command, Type type, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default) { - return command.DbConnection.QuerySingleAsync(type: type, sql: command.Sql, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType); + return command.DbConnection.QuerySingleAsync(type: type, command: new CommandDefinition(commandText: command.Sql, parameters: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, cancellationToken: cancellationToken)); } + /// /// Executes the query (using Dapper), returning the data typed as type. /// - public static Task QuerySingleOrDefaultAsync(this IDapperSqlCommand command, Type type, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null) + public static Task QuerySingleOrDefaultAsync(this IDapperSqlCommand command, Type type, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default) { - return command.DbConnection.QuerySingleOrDefaultAsync(type: type, sql: command.Sql, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType); + return command.DbConnection.QuerySingleOrDefaultAsync(type: type, command: new CommandDefinition(commandText: command.Sql, parameters: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, cancellationToken: cancellationToken)); } #endregion @@ -348,9 +355,9 @@ public static IDataReader ExecuteReader(this IDapperSqlCommand command, IDbTrans /// /// Executes the query (using Dapper), returning an System.Data.IDataReader /// - public static Task ExecuteReaderAsync(this IDapperSqlCommand command, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null) + public static Task ExecuteReaderAsync(this IDapperSqlCommand command, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default) { - return command.DbConnection.ExecuteReaderAsync(sql: command.Sql, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType); + return command.DbConnection.ExecuteReaderAsync(new CommandDefinition(commandText: command.Sql, parameters: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, cancellationToken: cancellationToken)); } #endregion @@ -362,6 +369,7 @@ public static Task ExecuteReaderAsync(this IDapperSqlCommand comman /// The first type in the recordset. /// The second type in the recordset. /// The combined type to return. + /// IDapperSqlCommand used to query the DbConnection. /// The function to map row types to the return type. /// The transaction to use for this query. /// Whether to buffer the results in memory. @@ -369,7 +377,7 @@ public static Task ExecuteReaderAsync(this IDapperSqlCommand comman /// Number of seconds before command execution timeout. /// Is it a stored proc or a batch? /// An enumerable of . - public static IEnumerable Query(this IDapperSqlCommand command, Func map, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null) + public static IEnumerable Query(this IDapperSqlCommand command, Func map, IDbTransaction? transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null) { return command.DbConnection.Query(sql: command.Sql, map: map, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, buffered: buffered, splitOn: splitOn); } @@ -383,6 +391,7 @@ public static IEnumerable Query(this IDapperS /// The second type in the recordset. /// The third type in the recordset. /// The combined type to return. + /// IDapperSqlCommand used to query the DbConnection. /// The function to map row types to the return type. /// The transaction to use for this query. /// Whether to buffer the results in memory. @@ -390,7 +399,7 @@ public static IEnumerable Query(this IDapperS /// Number of seconds before command execution timeout. /// Is it a stored proc or a batch? /// An enumerable of . - public static IEnumerable Query(this IDapperSqlCommand command, Func map, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null) + public static IEnumerable Query(this IDapperSqlCommand command, Func map, IDbTransaction? transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null) { return command.DbConnection.Query(sql: command.Sql, map: map, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, buffered: buffered, splitOn: splitOn); } @@ -404,6 +413,7 @@ public static IEnumerable Query(this /// The third type in the recordset. /// The fourth type in the recordset. /// The combined type to return. + /// IDapperSqlCommand used to query the DbConnection. /// The function to map row types to the return type. /// The transaction to use for this query. /// Whether to buffer the results in memory. @@ -411,7 +421,7 @@ public static IEnumerable Query(this /// Number of seconds before command execution timeout. /// Is it a stored proc or a batch? /// An enumerable of . - public static IEnumerable Query(this IDapperSqlCommand command, Func map, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null) + public static IEnumerable Query(this IDapperSqlCommand command, Func map, IDbTransaction? transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null) { return command.DbConnection.Query(sql: command.Sql, map: map, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, buffered: buffered, splitOn: splitOn); } @@ -426,6 +436,7 @@ public static IEnumerable QueryThe fourth type in the recordset. /// The fifth type in the recordset. /// The combined type to return. + /// IDapperSqlCommand used to query the DbConnection. /// The function to map row types to the return type. /// The transaction to use for this query. /// Whether to buffer the results in memory. @@ -433,7 +444,7 @@ public static IEnumerable QueryNumber of seconds before command execution timeout. /// Is it a stored proc or a batch? /// An enumerable of . - public static IEnumerable Query(this IDapperSqlCommand command, Func map, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null) + public static IEnumerable Query(this IDapperSqlCommand command, Func map, IDbTransaction? transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null) { return command.DbConnection.Query(sql: command.Sql, map: map, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, buffered: buffered, splitOn: splitOn); } @@ -449,6 +460,7 @@ public static IEnumerable QueryThe fifth type in the recordset. /// The sixth type in the recordset. /// The combined type to return. + /// IDapperSqlCommand used to query the DbConnection. /// The function to map row types to the return type. /// The transaction to use for this query. /// Whether to buffer the results in memory. @@ -456,7 +468,7 @@ public static IEnumerable QueryNumber of seconds before command execution timeout. /// Is it a stored proc or a batch? /// An enumerable of . - public static IEnumerable Query(this IDapperSqlCommand command, Func map, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null) + public static IEnumerable Query(this IDapperSqlCommand command, Func map, IDbTransaction? transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null) { return command.DbConnection.Query(sql: command.Sql, map: map, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, buffered: buffered, splitOn: splitOn); } @@ -473,6 +485,7 @@ public static IEnumerable QueryThe sixth type in the recordset. /// The seventh type in the recordset. /// The combined type to return. + /// IDapperSqlCommand used to query the DbConnection. /// The function to map row types to the return type. /// The transaction to use for this query. /// Whether to buffer the results in memory. @@ -480,7 +493,7 @@ public static IEnumerable QueryNumber of seconds before command execution timeout. /// Is it a stored proc or a batch? /// An enumerable of . - public static IEnumerable Query(this IDapperSqlCommand command, Func map, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null) + public static IEnumerable Query(this IDapperSqlCommand command, Func map, IDbTransaction? transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null) { return command.DbConnection.Query(sql: command.Sql, map: map, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, buffered: buffered, splitOn: splitOn); } @@ -490,6 +503,7 @@ public static IEnumerable Query. /// /// The combined type to return. + /// IDapperSqlCommand used to query the DbConnection. /// Array of types in the recordset. /// The function to map row types to the return type. /// The transaction to use for this query. @@ -498,7 +512,7 @@ public static IEnumerable QueryNumber of seconds before command execution timeout. /// Is it a stored proc or a batch? /// An enumerable of . - public static IEnumerable Query(this IDapperSqlCommand command, Type[] types, Func map, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null) + public static IEnumerable Query(this IDapperSqlCommand command, Type[] types, Func map, IDbTransaction? transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null) { return command.DbConnection.Query(sql: command.Sql, types, map: map, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, buffered: buffered, splitOn: splitOn); } @@ -513,19 +527,20 @@ public static IEnumerable Query(this IDapperSqlCommand command /// The first type in the recordset. /// The second type in the recordset. /// The combined type to return. + /// IDapperSqlCommand used to query the DbConnection. /// The function to map row types to the return type. /// The transaction to use for this query. /// Whether to buffer the results in memory. /// The field we should split and read the second object from (default: "Id"). /// Number of seconds before command execution timeout. /// Is it a stored proc or a batch? + /// The cancellation token for this command. /// An enumerable of . - public static Task> QueryAsync(this IDapperSqlCommand command, Func map, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null) + public static Task> QueryAsync(this IDapperSqlCommand command, Func map, IDbTransaction? transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default) { - return command.DbConnection.QueryAsync(sql: command.Sql, map: map, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, buffered: buffered, splitOn: splitOn); + return command.DbConnection.QueryAsync(command: new CommandDefinition(commandText: command.Sql, parameters: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, flags: buffered ? CommandFlags.Buffered : CommandFlags.None, cancellationToken: cancellationToken), map: map, splitOn: splitOn); } - /// /// Perform a multi-mapping query with 3 input types. /// This returns a single type, combined from the raw types via . @@ -534,16 +549,18 @@ public static Task> QueryAsync(th /// The second type in the recordset. /// The third type in the recordset. /// The combined type to return. + /// IDapperSqlCommand used to query the DbConnection. /// The function to map row types to the return type. /// The transaction to use for this query. /// Whether to buffer the results in memory. /// The field we should split and read the second object from (default: "Id"). /// Number of seconds before command execution timeout. /// Is it a stored proc or a batch? + /// The cancellation token for this command. /// An enumerable of . - public static Task> QueryAsync(this IDapperSqlCommand command, Func map, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null) + public static Task> QueryAsync(this IDapperSqlCommand command, Func map, IDbTransaction? transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default) { - return command.DbConnection.QueryAsync(sql: command.Sql, map: map, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, buffered: buffered, splitOn: splitOn); + return command.DbConnection.QueryAsync(command: new CommandDefinition(commandText: command.Sql, parameters: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, flags: buffered ? CommandFlags.Buffered : CommandFlags.None, cancellationToken: cancellationToken), map: map, splitOn: splitOn); } /// @@ -555,16 +572,18 @@ public static Task> QueryAsyncThe third type in the recordset. /// The fourth type in the recordset. /// The combined type to return. + /// IDapperSqlCommand used to query the DbConnection. /// The function to map row types to the return type. /// The transaction to use for this query. /// Whether to buffer the results in memory. /// The field we should split and read the second object from (default: "Id"). /// Number of seconds before command execution timeout. /// Is it a stored proc or a batch? + /// The cancellation token for this command. /// An enumerable of . - public static Task> QueryAsync(this IDapperSqlCommand command, Func map, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null) + public static Task> QueryAsync(this IDapperSqlCommand command, Func map, IDbTransaction? transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default) { - return command.DbConnection.QueryAsync(sql: command.Sql, map: map, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, buffered: buffered, splitOn: splitOn); + return command.DbConnection.QueryAsync(command: new CommandDefinition(commandText: command.Sql, parameters: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, flags: buffered ? CommandFlags.Buffered : CommandFlags.None, cancellationToken: cancellationToken), map: map, splitOn: splitOn); } /// @@ -577,16 +596,18 @@ public static Task> QueryAsyncThe fourth type in the recordset. /// The fifth type in the recordset. /// The combined type to return. + /// IDapperSqlCommand used to query the DbConnection. /// The function to map row types to the return type. /// The transaction to use for this query. /// Whether to buffer the results in memory. /// The field we should split and read the second object from (default: "Id"). /// Number of seconds before command execution timeout. /// Is it a stored proc or a batch? + /// The cancellation token for this command. /// An enumerable of . - public static Task> QueryAsync(this IDapperSqlCommand command, Func map, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null) + public static Task> QueryAsync(this IDapperSqlCommand command, Func map, IDbTransaction? transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default) { - return command.DbConnection.QueryAsync(sql: command.Sql, map: map, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, buffered: buffered, splitOn: splitOn); + return command.DbConnection.QueryAsync(command: new CommandDefinition(commandText: command.Sql, parameters: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, flags: buffered ? CommandFlags.Buffered : CommandFlags.None, cancellationToken: cancellationToken), map: map, splitOn: splitOn); } /// @@ -600,16 +621,18 @@ public static Task> QueryAsyncThe fifth type in the recordset. /// The sixth type in the recordset. /// The combined type to return. + /// IDapperSqlCommand used to query the DbConnection. /// The function to map row types to the return type. /// The transaction to use for this query. /// Whether to buffer the results in memory. /// The field we should split and read the second object from (default: "Id"). /// Number of seconds before command execution timeout. /// Is it a stored proc or a batch? + /// The cancellation token for this command. /// An enumerable of . - public static Task> QueryAsync(this IDapperSqlCommand command, Func map, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null) + public static Task> QueryAsync(this IDapperSqlCommand command, Func map, IDbTransaction? transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default) { - return command.DbConnection.QueryAsync(sql: command.Sql, map: map, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, buffered: buffered, splitOn: splitOn); + return command.DbConnection.QueryAsync(command: new CommandDefinition(commandText: command.Sql, parameters: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, flags: buffered ? CommandFlags.Buffered : CommandFlags.None, cancellationToken: cancellationToken), map: map, splitOn: splitOn); } /// @@ -624,16 +647,18 @@ public static Task> QueryAsyncThe sixth type in the recordset. /// The seventh type in the recordset. /// The combined type to return. + /// IDapperSqlCommand used to query the DbConnection. /// The function to map row types to the return type. /// The transaction to use for this query. /// Whether to buffer the results in memory. /// The field we should split and read the second object from (default: "Id"). /// Number of seconds before command execution timeout. /// Is it a stored proc or a batch? + /// The cancellation token for this command. /// An enumerable of . - public static Task> QueryAsync(this IDapperSqlCommand command, Func map, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null) + public static Task> QueryAsync(this IDapperSqlCommand command, Func map, IDbTransaction? transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default) { - return command.DbConnection.QueryAsync(sql: command.Sql, map: map, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, buffered: buffered, splitOn: splitOn); + return command.DbConnection.QueryAsync(command: new CommandDefinition(commandText: command.Sql, parameters: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, flags: buffered ? CommandFlags.Buffered : CommandFlags.None, cancellationToken: cancellationToken), map: map, splitOn: splitOn); } /// @@ -641,6 +666,7 @@ public static Task> QueryAsync. /// /// The combined type to return. + /// IDapperSqlCommand used to query the DbConnection. /// Array of types in the recordset. /// The function to map row types to the return type. /// The transaction to use for this query. @@ -648,14 +674,13 @@ public static Task> QueryAsyncThe field we should split and read the second object from (default: "Id"). /// Number of seconds before command execution timeout. /// Is it a stored proc or a batch? + /// The cancellation token for this command. /// An enumerable of . - public static Task> QueryAsync(this IDapperSqlCommand command, Type[] types, Func map, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null) + public static Task> QueryAsync(this IDapperSqlCommand command, Type[] types, Func map, IDbTransaction? transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null, CancellationToken cancellationToken = default) { - return command.DbConnection.QueryAsync(sql: command.Sql, types, map: map, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, buffered: buffered, splitOn: splitOn); + return command.DbConnection.QueryAsync(sql: command.Sql, param: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, buffered: buffered, types: types, map: map, splitOn: splitOn); + // return command.DbConnection.QueryAsync(command: new CommandDefinition(commandText: command.Sql, parameters: ParametersDictionary.LoadFrom(command), transaction: transaction, commandTimeout: commandTimeout, commandType: commandType, flags: buffered ? CommandFlags.Buffered : CommandFlags.None, cancellationToken: cancellationToken), types: types, map: map, splitOn: splitOn); } - #endregion - - } }