Commit dfbcaa16 authored by Nick Craver's avatar Nick Craver

Test and fix for #591

This brings behavior QueryAsync behavior on par with Query (sync) and properly returns nothing when an empty result set is encountered.
parent 80231b4d
using System;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using Xunit;
namespace Dapper.Tests
......@@ -219,7 +220,7 @@ select DATEADD(ns, -100, @b)
Assert.Equal(datetime2, p.Get<DateTime>("b"));
}
[Theory()]
[Theory]
[InlineData(null)]
[InlineData(DbType.DateTime)]
public void TestDateTime2LosePrecisionInDynamicParameters(DbType? dbType)
......@@ -254,5 +255,27 @@ select @b
// @b gets set to datetime2 value but is truncated back to DbType.DateTime by DynamicParameter's Output declaration
Assert.Equal(datetimeDefault, p.Get<DateTime>("b"));
}
[Fact]
public async Task Issue591_NoResultsAsync()
{
const string tempSPName = "#" + nameof(Issue591_NoResultsAsync);
var result = await connection.QueryAsync(
$@"create proc {tempSPName}
as
begin
-- basically a failed if statement, so the select is not happening and the stored proc return nothing
if 1=0
begin
select 1 as Num
end
end
exec {tempSPName}");
Assert.Empty(result);
}
}
}
......@@ -392,6 +392,8 @@ private static async Task<IEnumerable<T>> QueryAsync<T>(this IDbConnection cnn,
int hash = GetColumnHash(reader);
if (tuple.Func == null || tuple.Hash != hash)
{
if (reader.FieldCount == 0)
return Enumerable.Empty<T>();
tuple = info.Deserializer = new DeserializerState(hash, GetDeserializer(effectiveType, reader, 0, -1, false));
if (command.AddToCache) SetQueryCache(identity, info);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment