Good afternoon!
I have a method that adds a SQL parameter with the right SQLtype based
on a CLR type:
public void AddParam<T>(str ing name, T value)
{
...
}
I translate 'T' to a valid DbType. The problem is when T is Nullable,
as in
AddParam<int?>( name, x);
How can I get the 'int' from 'int?' inside AddParam() so I can
translate the type & handle NULLs properly?
Things I've tried:
* Nullable.ToObje ct<T>(value) returns a boxed object.
* value ?? value returns a T?
* Nullable.ValueO rDefault<T>(val ue) returns a boxed object.
* Try a Nullable-specific AddParam<T>(... ) where T : Nullable but that
complains about static structures as a constraint.
* Assign value directly to the SQL procedure but I get a "No mapping
exists from object type System.Nullable to a known managed provider
native type."
Thanks!
-Brian
I have a method that adds a SQL parameter with the right SQLtype based
on a CLR type:
public void AddParam<T>(str ing name, T value)
{
...
}
I translate 'T' to a valid DbType. The problem is when T is Nullable,
as in
AddParam<int?>( name, x);
How can I get the 'int' from 'int?' inside AddParam() so I can
translate the type & handle NULLs properly?
Things I've tried:
* Nullable.ToObje ct<T>(value) returns a boxed object.
* value ?? value returns a T?
* Nullable.ValueO rDefault<T>(val ue) returns a boxed object.
* Try a Nullable-specific AddParam<T>(... ) where T : Nullable but that
complains about static structures as a constraint.
* Assign value directly to the SQL procedure but I get a "No mapping
exists from object type System.Nullable to a known managed provider
native type."
Thanks!
-Brian
Comment