diff --git a/Dapper/SqlMapper.Async.cs b/Dapper/SqlMapper.Async.cs index fb7ce448c..eade08cb2 100644 --- a/Dapper/SqlMapper.Async.cs +++ b/Dapper/SqlMapper.Async.cs @@ -503,6 +503,7 @@ private static async Task QueryRowAsync(this IDbConnection cnn, Row row, T ThrowZeroRows(row); } while (await reader.NextResultAsync(cancel).ConfigureAwait(false)) { /* ignore result sets after the first */ } + command.OnCompleted(); return result; } finally diff --git a/tests/Dapper.Tests/AsyncTests.cs b/tests/Dapper.Tests/AsyncTests.cs index ec83dc2d9..9c3ec4721 100644 --- a/tests/Dapper.Tests/AsyncTests.cs +++ b/tests/Dapper.Tests/AsyncTests.cs @@ -667,6 +667,34 @@ public async Task TestSupportForDynamicParametersOutputExpressions_Query_Default Assert.Equal(42, result); } + [Fact] + public async Task TestSupportForDynamicParametersOutputExpressions_QueryFirst() + { + var bob = new Person { Name = "bob", PersonId = 1, Address = new Address { PersonId = 2 } }; + + var p = new DynamicParameters(bob); + p.Output(bob, b => b.PersonId); + p.Output(bob, b => b.Occupation); + p.Output(bob, b => b.NumberOfLegs); + p.Output(bob, b => b.Address!.Name); + p.Output(bob, b => b.Address!.PersonId); + + var result = (await connection.QueryFirstAsync(@" +SET @Occupation = 'grillmaster' +SET @PersonId = @PersonId + 1 +SET @NumberOfLegs = @NumberOfLegs - 1 +SET @AddressName = 'bobs burgers' +SET @AddressPersonId = @PersonId +select 42", p).ConfigureAwait(false)); + + Assert.Equal("grillmaster", bob.Occupation); + Assert.Equal(2, bob.PersonId); + Assert.Equal(1, bob.NumberOfLegs); + Assert.Equal("bobs burgers", bob.Address.Name); + Assert.Equal(2, bob.Address.PersonId); + Assert.Equal(42, result); + } + [Fact] public async Task TestSupportForDynamicParametersOutputExpressions_Query_BufferedAsync() {