Commit c3e7dbc9 authored by Sam Saffron's avatar Sam Saffron

fixed #47 Get now supports DBNull properly

parent 9ec29b77
......@@ -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% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment