From 834ccba14f56154010661fbdfb0b867f18aa14f2 Mon Sep 17 00:00:00 2001 From: Marc Gravell Date: Wed, 13 Sep 2023 14:35:52 +0100 Subject: [PATCH 1/2] - add missing ReadUnbufferedAsync untyped API - remove an impossible branch --- Dapper/PublicAPI/net5.0/PublicAPI.Shipped.txt | 1 + Dapper/SqlMapper.GridReader.Async.cs | 7 +++++-- tests/Dapper.Tests/AsyncTests.cs | 20 +++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/Dapper/PublicAPI/net5.0/PublicAPI.Shipped.txt b/Dapper/PublicAPI/net5.0/PublicAPI.Shipped.txt index 7e50a2832..5da46e604 100644 --- a/Dapper/PublicAPI/net5.0/PublicAPI.Shipped.txt +++ b/Dapper/PublicAPI/net5.0/PublicAPI.Shipped.txt @@ -1,5 +1,6 @@ #nullable enable Dapper.SqlMapper.GridReader.DisposeAsync() -> System.Threading.Tasks.ValueTask +Dapper.SqlMapper.GridReader.ReadUnbufferedAsync() -> System.Collections.Generic.IAsyncEnumerable! Dapper.SqlMapper.GridReader.ReadUnbufferedAsync() -> System.Collections.Generic.IAsyncEnumerable! static Dapper.SqlMapper.QueryUnbufferedAsync(this System.Data.Common.DbConnection! cnn, string! sql, object? param = null, System.Data.Common.DbTransaction? transaction = null, int? commandTimeout = null, System.Data.CommandType? commandType = null) -> System.Collections.Generic.IAsyncEnumerable! static Dapper.SqlMapper.QueryUnbufferedAsync(this System.Data.Common.DbConnection! cnn, string! sql, object? param = null, System.Data.Common.DbTransaction? transaction = null, int? commandTimeout = null, System.Data.CommandType? commandType = null) -> System.Collections.Generic.IAsyncEnumerable! \ No newline at end of file diff --git a/Dapper/SqlMapper.GridReader.Async.cs b/Dapper/SqlMapper.GridReader.Async.cs index 770a04c12..5b5b9b73d 100644 --- a/Dapper/SqlMapper.GridReader.Async.cs +++ b/Dapper/SqlMapper.GridReader.Async.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Data.Common; -using System.Linq; using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; @@ -180,7 +179,6 @@ private Task> ReadAsyncImpl(Type type, bool buffered) else { var result = ReadDeferred(index, deserializer, type); - if (buffered) result = result.ToList(); // for the "not a DbDataReader" scenario return Task.FromResult(result); } } @@ -256,6 +254,11 @@ private async Task> ReadBufferedAsync(int index, FuncThe type to read. public IAsyncEnumerable ReadUnbufferedAsync() => ReadAsyncUnbufferedImpl(typeof(T)); + /// + /// Read the next grid of results. + /// + public IAsyncEnumerable ReadUnbufferedAsync() => ReadAsyncUnbufferedImpl(typeof(DapperRow)); + private IAsyncEnumerable ReadAsyncUnbufferedImpl(Type type) { var deserializer = ValidateAndMarkConsumed(type, out var index); diff --git a/tests/Dapper.Tests/AsyncTests.cs b/tests/Dapper.Tests/AsyncTests.cs index f3a1597a2..7a9abf2d1 100644 --- a/tests/Dapper.Tests/AsyncTests.cs +++ b/tests/Dapper.Tests/AsyncTests.cs @@ -112,6 +112,26 @@ public async Task TestBasicStringUsageViaGridReaderUnbufferedAsync() Assert.Equal(new[] { "abc", "def", "ghi" }, arr); } + [Fact] + public async Task TestBasicStringUsageViaGridReaderUnbufferedDynamicAsync() + { + var results = new List(); + await using (var grid = await connection.QueryMultipleAsync("select 'abc' as [Foo] union select 'def'; select @txt as [Foo]", new { txt = "ghi" }) + .ConfigureAwait(false)) + { + while (!grid.IsConsumed) + { + await foreach (var value in grid.ReadUnbufferedAsync() + .ConfigureAwait(false)) + { + results.Add((string)value.Foo); + } + } + } + var arr = results.ToArray(); + Assert.Equal(new[] { "abc", "def", "ghi" }, arr); + } + [Fact] public async Task TestBasicStringUsageViaGridReaderUnbufferedAsync_Cancellation() { From 658c431ffbb72d325489305dc7b069854e55ec71 Mon Sep 17 00:00:00 2001 From: Marc Gravell Date: Wed, 13 Sep 2023 14:51:22 +0100 Subject: [PATCH 2/2] release notes --- docs/index.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/index.md b/docs/index.md index 40f5b0d0a..e2273bb74 100644 --- a/docs/index.md +++ b/docs/index.md @@ -24,6 +24,8 @@ Note: to get the latest pre-release build, add ` -Pre` to the end of the command (note: new PRs will not be merged until they add release note wording here) +- add untyped `GridReader.ReadUnbufferedAsync` API (#1958 via @mgravell) + ### 2.1.1 - add NRT annotations (#1928 via @mgravell)