diff --git a/Dapper.Tests/Tests.Async.cs b/Dapper.Tests/Tests.Async.cs index 4994855a2..c61753e16 100644 --- a/Dapper.Tests/Tests.Async.cs +++ b/Dapper.Tests/Tests.Async.cs @@ -20,6 +20,34 @@ public async Task TestBasicStringUsageAsync() arr.IsSequenceEqualTo(new[] { "abc", "def" }); } + [Fact] + public async Task TestBasicStringUsageQueryFirstAsync() + { + var str = await connection.QueryFirstAsync(new CommandDefinition("select 'abc' as [Value] union all select @txt", new {txt = "def"})); + str.IsEqualTo("abc"); + } + + [Fact] + public async Task TestBasicStringUsageQueryFirstOrDefaultAsync() + { + var str = await connection.QueryFirstOrDefaultAsync(new CommandDefinition("select null as [Value] union all select @txt", new {txt = "def"})); + str.IsNull(); + } + + [Fact] + public async Task TestBasicStringUsageQuerySingleAsync() + { + var str = await connection.QuerySingleAsync(new CommandDefinition("select 'abc' as [Value]")); + str.IsEqualTo("abc"); + } + + [Fact] + public async Task TestBasicStringUsageQuerySingleOrDefaultAsync() + { + var str = await connection.QuerySingleAsync(new CommandDefinition("select null as [Value]")); + str.IsNull(); + } + [Fact] public async Task TestBasicStringUsageAsyncNonBuffered() { diff --git a/Dapper/SqlMapper.Async.cs b/Dapper/SqlMapper.Async.cs index 5be5815f9..1572749d4 100644 --- a/Dapper/SqlMapper.Async.cs +++ b/Dapper/SqlMapper.Async.cs @@ -168,6 +168,13 @@ public static Task QueryFirstAsync(this IDbConnection cnn, Type type, Co /// /// Execute a single-row query asynchronously using .NET 4.5 Task. /// + public static Task QueryFirstAsync(this IDbConnection cnn, CommandDefinition command) + { + return QueryRowAsync(cnn, Row.First, typeof(T), command); + } + /// + /// Execute a single-row query asynchronously using .NET 4.5 Task. + /// public static Task QueryFirstOrDefaultAsync(this IDbConnection cnn, Type type, CommandDefinition command) { return QueryRowAsync(cnn, Row.FirstOrDefault, type, command); @@ -175,6 +182,13 @@ public static Task QueryFirstOrDefaultAsync(this IDbConnection cnn, Type /// /// Execute a single-row query asynchronously using .NET 4.5 Task. /// + public static Task QueryFirstOrDefaultAsync(this IDbConnection cnn, CommandDefinition command) + { + return QueryRowAsync(cnn, Row.FirstOrDefault, typeof(T), command); + } + /// + /// Execute a single-row query asynchronously using .NET 4.5 Task. + /// public static Task QuerySingleAsync(this IDbConnection cnn, Type type, CommandDefinition command) { return QueryRowAsync(cnn, Row.Single, type, command); @@ -182,11 +196,24 @@ public static Task QuerySingleAsync(this IDbConnection cnn, Type type, C /// /// Execute a single-row query asynchronously using .NET 4.5 Task. /// + public static Task QuerySingleAsync(this IDbConnection cnn, CommandDefinition command) + { + return QueryRowAsync(cnn, Row.Single, typeof(T), command); + } + /// + /// Execute a single-row query asynchronously using .NET 4.5 Task. + /// public static Task QuerySingleOrDefaultAsync(this IDbConnection cnn, Type type, CommandDefinition command) { return QueryRowAsync(cnn, Row.SingleOrDefault, type, command); } - + /// + /// Execute a single-row query asynchronously using .NET 4.5 Task. + /// + public static Task QuerySingleOrDefaultAsync(this IDbConnection cnn, CommandDefinition command) + { + return QueryRowAsync(cnn, Row.SingleOrDefault, typeof(T), command); + } private static Task ExecuteReaderWithFlagsFallbackAsync(DbCommand cmd, bool wasClosed, CommandBehavior behavior, CancellationToken cancellationToken) {