Commit 4aef740a authored by Sam Saffron's avatar Sam Saffron

fix some bugs around list of ints and strings

allos for datetime
parent bc5bcf50
......@@ -30,10 +30,28 @@ static SqlMapper()
typeMap[typeof(Guid)] = SqlDbType.UniqueIdentifier;
typeMap[typeof(Guid?)] = SqlDbType.UniqueIdentifier;
typeMap[typeof(int[])] = SqlDbType.Structured;
typeMap[typeof(List<int>)] = SqlDbType.Structured;
typeMap[typeof(string[])] = SqlDbType.Structured;
typeMap[typeof(List<string>)] = SqlDbType.Structured;
typeMap[typeof(DateTime)] = SqlDbType.DateTime;
typeMap[typeof(DateTime?)] = SqlDbType.DateTime;
}
private static SqlDbType LookupDbType(Type type)
{
SqlDbType dbType;
if (typeMap.TryGetValue(type, out dbType))
{
return dbType;
}
else
{
if (typeof(IEnumerable<int>).IsAssignableFrom(type) || typeof(IEnumerable<string>).IsAssignableFrom(type))
{
return SqlDbType.Structured;
}
}
throw new NotSupportedException("The type : " + type.ToString() + " is not supported by the mapper");
}
......@@ -193,7 +211,7 @@ private static object GetDynamicDeserializer(SqlDataReader reader)
il.Emit(OpCodes.Dup); // stack is now [list] [list]
il.Emit(OpCodes.Ldstr, prop.Name); // stack is [list] [list] [name]
il.Emit(OpCodes.Ldc_I4, (int)typeMap[prop.PropertyType]); // stack is [list] [list] [name] [dbtype]
il.Emit(OpCodes.Ldc_I4, (int)LookupDbType(prop.PropertyType)); // stack is [list] [list] [name] [dbtype]
il.Emit(OpCodes.Ldloc_0); // stack is [list] [list] [name] [dbtype] [typed-param]
il.Emit(OpCodes.Callvirt, prop.GetGetMethod()); // stack is [list] [list] [name] [dbtype] [typed-value]
if (prop.PropertyType.IsValueType)
......
......@@ -56,7 +56,7 @@ public void SelectListInt()
public void PassInIntArray()
{
connection.ExecuteMapperQuery<int>("select * from @Ids", new { Ids = new int[] { 1, 2, 3 } })
connection.ExecuteMapperQuery<int>("select * from @Ids", new { Ids = new int[] { 1, 2, 3 }.AsEnumerable() })
.IsSequenceEqual(new[] { 1, 2, 3 });
}
......
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