Commit 6e9099d6 authored by Brian Drupieski's avatar Brian Drupieski Committed by Nick Craver

fix Insert<T> when T is declared as IEnumerable<T> (#948)

parent 07fe543f
......@@ -148,11 +148,19 @@ public static partial class SqlMapperExtensions
isList = true;
type = type.GetElementType();
}
else if (type.IsGenericType() && type.GetTypeInfo().ImplementedInterfaces.Any(ti => ti.IsGenericType() && ti.GetGenericTypeDefinition() == typeof(IEnumerable<>)))
else if (type.IsGenericType())
{
var typeInfo = type.GetTypeInfo();
bool implementsGenericIEnumerableOrIsGenericIEnumerable =
typeInfo.ImplementedInterfaces.Any(ti => ti.IsGenericType() && ti.GetGenericTypeDefinition() == typeof(IEnumerable<>)) ||
typeInfo.GetGenericTypeDefinition() == typeof(IEnumerable<>);
if (implementsGenericIEnumerableOrIsGenericIEnumerable)
{
isList = true;
type = type.GetGenericArguments()[0];
}
}
var name = GetTableName(type);
var sbColumnList = new StringBuilder(null);
......
......@@ -332,11 +332,19 @@ private static string GetTableName(Type type)
isList = true;
type = type.GetElementType();
}
else if (type.IsGenericType() && type.GetTypeInfo().ImplementedInterfaces.Any(ti => ti.IsGenericType() && ti.GetGenericTypeDefinition() == typeof(IEnumerable<>)))
else if (type.IsGenericType())
{
var typeInfo = type.GetTypeInfo();
bool implementsGenericIEnumerableOrIsGenericIEnumerable =
typeInfo.ImplementedInterfaces.Any(ti => ti.IsGenericType() && ti.GetGenericTypeDefinition() == typeof(IEnumerable<>)) ||
typeInfo.GetGenericTypeDefinition() == typeof(IEnumerable<>);
if (implementsGenericIEnumerableOrIsGenericIEnumerable)
{
isList = true;
type = type.GetGenericArguments()[0];
}
}
var name = GetTableName(type);
var sbColumnList = new StringBuilder(null);
......
......@@ -225,6 +225,12 @@ public async Task BuilderTemplateWithoutCompositionAsync()
}
}
[Fact]
public async Task InsertEnumerableAsync()
{
await InsertHelperAsync(src => src.AsEnumerable()).ConfigureAwait(false);
}
[Fact]
public async Task InsertArrayAsync()
{
......
......@@ -324,6 +324,12 @@ public void TestClosedConnection()
}
}
[Fact]
public void InsertEnumerable()
{
InsertHelper(src => src.AsEnumerable());
}
[Fact]
public void InsertArray()
{
......
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