Skip to content

Commit d994b6d

Browse files
ri-rgbRich
and
Rich
authored
OutputExpression wasn't working for methods that use QueryRowAsync (#2156)
Added command.OnCompleted() to QueryRowAsync Co-authored-by: Rich <Rich@XPS-15>
1 parent e97a919 commit d994b6d

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

Dapper/SqlMapper.Async.cs

+1
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,7 @@ private static async Task<T> QueryRowAsync<T>(this IDbConnection cnn, Row row, T
503503
ThrowZeroRows(row);
504504
}
505505
while (await reader.NextResultAsync(cancel).ConfigureAwait(false)) { /* ignore result sets after the first */ }
506+
command.OnCompleted();
506507
return result;
507508
}
508509
finally

tests/Dapper.Tests/AsyncTests.cs

+28
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,34 @@ public async Task TestSupportForDynamicParametersOutputExpressions_Query_Default
667667
Assert.Equal(42, result);
668668
}
669669

670+
[Fact]
671+
public async Task TestSupportForDynamicParametersOutputExpressions_QueryFirst()
672+
{
673+
var bob = new Person { Name = "bob", PersonId = 1, Address = new Address { PersonId = 2 } };
674+
675+
var p = new DynamicParameters(bob);
676+
p.Output(bob, b => b.PersonId);
677+
p.Output(bob, b => b.Occupation);
678+
p.Output(bob, b => b.NumberOfLegs);
679+
p.Output(bob, b => b.Address!.Name);
680+
p.Output(bob, b => b.Address!.PersonId);
681+
682+
var result = (await connection.QueryFirstAsync<int>(@"
683+
SET @Occupation = 'grillmaster'
684+
SET @PersonId = @PersonId + 1
685+
SET @NumberOfLegs = @NumberOfLegs - 1
686+
SET @AddressName = 'bobs burgers'
687+
SET @AddressPersonId = @PersonId
688+
select 42", p).ConfigureAwait(false));
689+
690+
Assert.Equal("grillmaster", bob.Occupation);
691+
Assert.Equal(2, bob.PersonId);
692+
Assert.Equal(1, bob.NumberOfLegs);
693+
Assert.Equal("bobs burgers", bob.Address.Name);
694+
Assert.Equal(2, bob.Address.PersonId);
695+
Assert.Equal(42, result);
696+
}
697+
670698
[Fact]
671699
public async Task TestSupportForDynamicParametersOutputExpressions_Query_BufferedAsync()
672700
{

0 commit comments

Comments
 (0)