Skip to content

Commit 61ff85a

Browse files
authored
add missing ReadUnbufferedAsync untyped API (#1958)
* - add missing ReadUnbufferedAsync untyped API - remove an impossible branch * release notes
1 parent a2d539c commit 61ff85a

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#nullable enable
22
Dapper.SqlMapper.GridReader.DisposeAsync() -> System.Threading.Tasks.ValueTask
3+
Dapper.SqlMapper.GridReader.ReadUnbufferedAsync() -> System.Collections.Generic.IAsyncEnumerable<dynamic!>!
34
Dapper.SqlMapper.GridReader.ReadUnbufferedAsync<T>() -> System.Collections.Generic.IAsyncEnumerable<T>!
45
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<dynamic!>!
56
static Dapper.SqlMapper.QueryUnbufferedAsync<T>(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<T>!

Dapper/SqlMapper.GridReader.Async.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Data.Common;
4-
using System.Linq;
54
using System.Runtime.CompilerServices;
65
using System.Threading;
76
using System.Threading.Tasks;
@@ -180,7 +179,6 @@ private Task<IEnumerable<T>> ReadAsyncImpl<T>(Type type, bool buffered)
180179
else
181180
{
182181
var result = ReadDeferred<T>(index, deserializer, type);
183-
if (buffered) result = result.ToList(); // for the "not a DbDataReader" scenario
184182
return Task.FromResult(result);
185183
}
186184
}
@@ -256,6 +254,11 @@ private async Task<IEnumerable<T>> ReadBufferedAsync<T>(int index, Func<DbDataRe
256254
/// <typeparam name="T">The type to read.</typeparam>
257255
public IAsyncEnumerable<T> ReadUnbufferedAsync<T>() => ReadAsyncUnbufferedImpl<T>(typeof(T));
258256

257+
/// <summary>
258+
/// Read the next grid of results.
259+
/// </summary>
260+
public IAsyncEnumerable<dynamic> ReadUnbufferedAsync() => ReadAsyncUnbufferedImpl<dynamic>(typeof(DapperRow));
261+
259262
private IAsyncEnumerable<T> ReadAsyncUnbufferedImpl<T>(Type type)
260263
{
261264
var deserializer = ValidateAndMarkConsumed(type, out var index);

docs/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Note: to get the latest pre-release build, add ` -Pre` to the end of the command
2424

2525
(note: new PRs will not be merged until they add release note wording here)
2626

27+
- add untyped `GridReader.ReadUnbufferedAsync` API (#1958 via @mgravell)
28+
2729
### 2.1.1
2830

2931
- add NRT annotations (#1928 via @mgravell)

tests/Dapper.Tests/AsyncTests.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,26 @@ public async Task TestBasicStringUsageViaGridReaderUnbufferedAsync()
112112
Assert.Equal(new[] { "abc", "def", "ghi" }, arr);
113113
}
114114

115+
[Fact]
116+
public async Task TestBasicStringUsageViaGridReaderUnbufferedDynamicAsync()
117+
{
118+
var results = new List<string>();
119+
await using (var grid = await connection.QueryMultipleAsync("select 'abc' as [Foo] union select 'def'; select @txt as [Foo]", new { txt = "ghi" })
120+
.ConfigureAwait(false))
121+
{
122+
while (!grid.IsConsumed)
123+
{
124+
await foreach (var value in grid.ReadUnbufferedAsync()
125+
.ConfigureAwait(false))
126+
{
127+
results.Add((string)value.Foo);
128+
}
129+
}
130+
}
131+
var arr = results.ToArray();
132+
Assert.Equal(new[] { "abc", "def", "ghi" }, arr);
133+
}
134+
115135
[Fact]
116136
public async Task TestBasicStringUsageViaGridReaderUnbufferedAsync_Cancellation()
117137
{

0 commit comments

Comments
 (0)