diff --git a/Dapper/CommandDefinition.cs b/Dapper/CommandDefinition.cs index 19963ba67..4af62e8bb 100644 --- a/Dapper/CommandDefinition.cs +++ b/Dapper/CommandDefinition.cs @@ -1,4 +1,5 @@ using System; +using System.Collections; using System.Data; using System.Reflection; using System.Reflection.Emit; @@ -21,6 +22,8 @@ internal void OnCompleted() (Parameters as SqlMapper.IParameterCallbacks)?.OnCompleted(); } + public IList? Buffer { get; } + /// /// The command (sql or a stored-procedure name) to execute /// @@ -83,7 +86,7 @@ internal void OnCompleted() /// The cancellation token for this command. public CommandDefinition(string commandText, object? parameters = null, IDbTransaction? transaction = null, int? commandTimeout = null, CommandType? commandType = null, CommandFlags flags = CommandFlags.Buffered - , CancellationToken cancellationToken = default + , CancellationToken cancellationToken = default, IList? buffer = null ) { CommandText = commandText; @@ -93,6 +96,7 @@ public CommandDefinition(string commandText, object? parameters = null, IDbTrans CommandTypeDirect = commandType ?? InferCommandType(commandText); Flags = flags; CancellationToken = cancellationToken; + Buffer = buffer; } internal static CommandType InferCommandType(string sql) diff --git a/Dapper/PublicAPI.Shipped.txt b/Dapper/PublicAPI.Shipped.txt index 456aa8bb1..39ea37508 100644 --- a/Dapper/PublicAPI.Shipped.txt +++ b/Dapper/PublicAPI.Shipped.txt @@ -10,6 +10,7 @@ Dapper.CommandDefinition.CancellationToken.get -> System.Threading.CancellationT Dapper.CommandDefinition.CommandDefinition() -> void Dapper.CommandDefinition.CommandDefinition(string! commandText, object? parameters = null, System.Data.IDbTransaction? transaction = null, int? commandTimeout = null, System.Data.CommandType? commandType = null, Dapper.CommandFlags flags = Dapper.CommandFlags.Buffered, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> void Dapper.CommandDefinition.CommandText.get -> string! +Dapper.CommandDefinition.Buffer.get -> IEnumerable? Dapper.CommandDefinition.CommandTimeout.get -> int? Dapper.CommandDefinition.CommandType.get -> System.Data.CommandType? Dapper.CommandDefinition.Flags.get -> Dapper.CommandFlags diff --git a/Dapper/SqlMapper.Async.cs b/Dapper/SqlMapper.Async.cs index eade08cb2..15598219e 100644 --- a/Dapper/SqlMapper.Async.cs +++ b/Dapper/SqlMapper.Async.cs @@ -447,7 +447,7 @@ private static async Task> QueryAsync(this IDbConnection cnn, if (command.Buffered) { - var buffer = new List(); + var buffer = command.Buffer as IList ?? new List(); var convertToType = Nullable.GetUnderlyingType(effectiveType) ?? effectiveType; while (await reader.ReadAsync(cancel).ConfigureAwait(false)) { @@ -473,6 +473,7 @@ private static async Task> QueryAsync(this IDbConnection cnn, if (wasClosed) cnn.Close(); } } + private static async Task QueryRowAsync(this IDbConnection cnn, Row row, Type effectiveType, CommandDefinition command) {