提交 aa98265b 编写于 作者: S Sam Saffron

fixed #47 Get now supports DBNull properly

上级 be18f157
......@@ -1586,7 +1586,16 @@ void SqlMapper.IDynamicParameters.AddParameters(IDbCommand command)
public T Get<T>(string name)
{
return (T)parameters[Clean(name)].AttachedParam.Value;
var val = parameters[Clean(name)].AttachedParam.Value;
if (val == DBNull.Value)
{
if (default(T) != null)
{
throw new ApplicationException("Attempting to cast a DBNull to a non nullable type!");
}
return default(T);
}
return (T)val;
}
}
public sealed class DbString
......
......@@ -1026,5 +1026,15 @@ public void TestMultiMapThreeTypesWithGridReader()
connection.Execute("drop table #Users drop table #Posts drop table #Comments");
}
public void TestDynamicParamNullSupport()
{
var p = new DynamicParameters();
p.Add("@b", dbType: DbType.Int32, direction: ParameterDirection.Output);
connection.Execute("select @b = null",p);
p.Get<int?>("@b").IsNull();
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册