yuan8825399 / dapper-dot-net

Automatically exported from code.google.com/p/dapper-dot-net
Other
0 stars 0 forks source link

Stored Procedure DBNull Output Parameter Casting Exception #47

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Create a sproc with an output parameter
2. In the sproc set the parameter to null
3. Use DynamicParameters to add an output parameter
4. Call sproc with dapper
5. Use DynamicParameters.Get<T> to get value

What is the expected output? What do you see instead?
For dbnulls to be treated as nulls and casted to the destination type 
accordingly. Getting an invalid cast exception instead @ 
"Dapper.DynamicParameters.Get[T](String name)" line 1589.

What version of the product are you using? On what operating system?
1.5, Windows 7, Sql Server 2008 R2

Please provide any additional information below.
Locally I've added a DBNull check to "public T Get<T>(string name)" changing it 
from:
(T)parameters[Clean(name)].AttachedParam.Value;

to

var value = parameters[Clean(name)].AttachedParam.Value;
return (T)(value == DBNull.Value ? null : value);

which works well enough.

Original issue reported on code.google.com by czy...@gmail.com on 15 Jul 2011 at 5:56

GoogleCodeExporter commented 9 years ago
cool ... sorted ... my fix is a tiny bit more fancy. 

Original comment by sam.saff...@gmail.com on 19 Jul 2011 at 5:07