提交 37dd9468 编写于 作者: M Marc Gravell

support enum params and nullable-T params

上级 22f8c33b
......@@ -187,6 +187,12 @@ static SqlMapper()
private static DbType LookupDbType(Type type)
{
DbType dbType;
var nullUnderlyingType = Nullable.GetUnderlyingType(type);
if (nullUnderlyingType != null) type = nullUnderlyingType;
if (type.IsEnum)
{
type = Enum.GetUnderlyingType(type);
}
if (typeMap.TryGetValue(type.TypeHandle, out dbType))
{
return dbType;
......@@ -197,6 +203,7 @@ private static DbType LookupDbType(Type type)
return DbType.Xml;
}
throw new NotSupportedException(string.Format("The type : {0} is not supported by dapper", type));
}
......
......@@ -97,6 +97,27 @@ public void TestStrings()
.IsSequenceEqualTo(new[] { "a", "b" });
}
enum EnumParam : short
{
None, A, B
}
class EnumParamObject
{
public EnumParam A { get; set; }
public EnumParam? B { get; set; }
public EnumParam? C { get; set; }
}
public void TestEnumParams()
{
EnumParam a = EnumParam.A;
EnumParam? b = EnumParam.B, c = null;
var obj = connection.Query<EnumParamObject>("select @a as A, @b as B, @c as C",
new { a, b, c }).Single();
obj.A.IsEqualTo(EnumParam.A);
obj.B.IsEqualTo(EnumParam.B);
obj.C.IsEqualTo(null);
}
public class Dog
{
public int? Age { get; set; }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册