Nulls and Value Types in Business Objects

  • Thread starter Thread starter Steve Landis
  • Start date Start date
S

Steve Landis

The business classes that we create for our applications have typically used
many value type properties like Int32, DateTime, Decimal, etc. that cannot
store null values. This is a problem, because we can't expose a property as
null and can't store null back to the database unless we use some ugly
workaround. We have started using the SqlTypes namespace to get around this
and this seems acceptable in c#, but not in VB.NET, which doesn't support
the operator overloading. We are curious what techniques others have used
to get around this issue? Do you allow nulls in the database? Do you
require entry of everything in the app? Do you use the SqlTypes? Do the
same issues arise in java?
 
Steve,
the operator overloading. We are curious what techniques others have used
to get around this issue?
I normally prevent the database NULL from making it back to the PC. I use
stored procedures to map database NULLs to PC friendly values. (zeros or
blanks normally). Of course this causes the problem of is it NULL or is it
blank. I take the approach If the field is nullable blank is mapped to NULL.

This "encapsulates" all the database NULL handling to the stored procedures,
which make for cleaner PC code.
Do you allow nulls in the database?
I normally reserve nulls for table references & truly optional information.
Which generally means only foreign keys are nullable.
Do you require entry of everything in the app?
Within the context of the above two, yes.
Do you use the SqlTypes?
Currently No, if I did use them in VB.NET they have methods to perform the
same operations as the overloaded operators.

// C#
SqlInt32 x, y, z;
x = y + z;

' VB.NET
Dim x, y, z As SqlInt32
x = SqlInt32.op_Addition(y, z)
' or
x = SqlInt32.Add(y, z)

NOTE: When Whidbey (VS.NET 2004) is available VB.NET will support operator
overloading.
Do the same issues arise in java?
Yes.

Hope this helps
Jay
 
Back
Top