SQLProvider icon indicating copy to clipboard operation
SQLProvider copied to clipboard

How to pass null/None to Procedure?

Open legomind opened this issue 9 years ago • 5 comments

CREATE PROCEDURE dbo.test (
    @OptionalParam INT = NULL
)
AS 

SELECT 1
//Snip...
[ for r in db.Procedures.test.Invoke(None).ResultSet
                  -> r.MapTo<TestResult> () ]
//Error: Expression was expected to have type int but here has type Option<int>

legomind avatar Sep 17 '15 13:09 legomind

You can't do this as the F# type system doesn't allow you to represent null as int. In cases like this I guess we could detect if the parameter is nullable (presuming the metadata is available) then the type of the parameter would be Nullable<int> which I think would cover your needs, or if PreferOptionals is set you would get Option<int>

colinbull avatar Sep 18 '15 08:09 colinbull

yes this should be pretty easy to do, we will get it in for the coming V1. It might be nice to put sprocs under their schemas as well, on an unrelated note. They can clash with each other at the moment.

pezipink avatar Sep 18 '15 09:09 pezipink

Cool. Looking forward to v1

On Fri, Sep 18, 2015, 5:00 AM Ross McKinlay [email protected] wrote:

yes this should be pretty easy to do, we will get it in for the coming V1. It might be nice to put sprocs under their schemas as well, on an unrelated note. They can clash with each other at the moment.

— Reply to this email directly or view it on GitHub https://github.com/fsprojects/SQLProvider/issues/158#issuecomment-141386069 .

legomind avatar Sep 18 '15 21:09 legomind

additionally, it might not be possible but if you set the stored procedure to have Null as a default parameter, and you pass null into the sproc, it will send 'default' to the sql, which uses the default value and all is ok

ghost avatar Nov 21 '15 05:11 ghost

Any updates on this?

JamesFaix avatar Jul 11 '19 09:07 JamesFaix