Paolo ponzano - 142 - Feb 17, 2014

Hello,
I think there’s a bug on how SS OrmLite handles null values…
I’ve a POCO like

 public class SomeDTO : IReturn<bool>
    {
        public int ID { get; set; }
        public int? OptionalID { get; set; }
    }

when I pass to ORMLite the field as null it generates the following statement

exec SP_xxx @ID=1602,OptionalID=default

If I set it as DBNull.Value it correctly hands null value… on StackOverflow there was an iussue #274 on this http://stackoverflow.com/questions/17432909/how-to-pass-non-optional-null-parameters-to-a-stored-proc-using-ormlite …wasn’t it supposed to be fixed?
Thanks

Are you calling a stored procedure? what’s the failing test look like?

paolo ponzano:

Yes it’s a procedure … I’m calling it as

 var lst = db.Exec(dbCmd =>
                {
                    dbCmd.CommandType = CommandType.StoredProcedure;
                    dbCmd.CommandText = storedProcedure;

                    dbCmd.Parameters.Add(new SqlParameter(“ID”, request.ID));
                    dbCmd.Parameters.Add(new SqlParameter(“OptionalID”, request.OptionalID)); //this sets default
                 return dbCmd.ExecuteNonQuery();

Your executing plain ADO.NET code at this point. OrmLite has no impact here.

paolo ponzano:

Ah ok…I’m using this way since with db.SqlProcedure I don’t know where to set the SP name…

Here are some examples calling SQL Server procs with the Sql* apis: https://github.com/ServiceStack/ServiceStack.OrmLite/blob/master/tests/ServiceStack.OrmLite.Tests/SqlServerProviderTests.cs

Here’s an example using the ExecuteProcedure method: https://github.com/ServiceStack/ServiceStack.OrmLite/blob/master/src/ServiceStack.OrmLite.PostgreSQL.Tests/OrmLiteExecuteProcedureTests.cs
It uses the name of the DTO - but the Sql* APIs offer more flexibility.