Commit c287693c authored by Nick Craver's avatar Nick Craver

Merge pull request #338 from phnx47/master

fix Cast at QueryAsync<T>
parents b77e5384 2ead2428
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Data; using System.Data;
using System.Data.Common; using System.Data.Common;
using System.Globalization;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
...@@ -107,9 +108,20 @@ private static async Task<IEnumerable<T>> QueryAsync<T>(this IDbConnection cnn, ...@@ -107,9 +108,20 @@ private static async Task<IEnumerable<T>> QueryAsync<T>(this IDbConnection cnn,
if (command.Buffered) if (command.Buffered)
{ {
List<T> buffer = new List<T>(); List<T> buffer = new List<T>();
var convertToType = Nullable.GetUnderlyingType(effectiveType) ?? effectiveType;
while (await reader.ReadAsync(cancel).ConfigureAwait(false)) while (await reader.ReadAsync(cancel).ConfigureAwait(false))
{ {
buffer.Add((T)func(reader)); object val = func(reader);
if (val == null || val is T)
{
buffer.Add((T) val);
}
else
{
buffer.Add((T)Convert.ChangeType(val, convertToType, CultureInfo.InvariantCulture));
}
} }
while (await reader.NextResultAsync().ConfigureAwait(false)) { } while (await reader.NextResultAsync().ConfigureAwait(false)) { }
command.OnCompleted(); command.OnCompleted();
......
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