views:

661

answers:

2

I'm trying to call a stored procedure with an output parameter from F#, so I need to pass an int? value initialized to null. However, F# is resisting my attempts, saying that the object cannot be null. I've read up on the web as to why that is but my problem remains - I need to call that stored procedure. Has anyone got any ideas as to how I can do it? Thanks.

+3  A: 

I do not believe that F# has a conversion from null -> empty Nullable. But if you instantiate a Nullable object, it will default to no value. This is the equivalent of passing null in C#/VB.

myStoredProc (new System.Nullable<int>())
JaredPar
Works for me, thanks!
Dmitri Nesteruk
+2  A: 

One nice thing that F# allows you to do is to declare "generic value" so you don't have to write the lengthly construction of the value all the time.

let gnull = new System.Nullable<_>();;

Now you can just use gnull whenever you need to pass null as a nullable to some function:

> let foo (a:System.Nullable<int>) = 0;;
val foo : System.Nullable<int> -> int

> foo gnull;;
val it : int = 0
Tomas Petricek