Managing optional dates in a business object

  • Thread starter Thread starter Eric Caron
  • Start date Start date
E

Eric Caron

Hi all,

I have a property in one of my classes that represents an optional date.
I'm trying to figure out if I can represent Null or Nothing as the value for
a Date data type. Branching in the data access layer to send a Null to the
stored procedure is no problem, but managing a Null date in the business
object is another matter. I'm thinking of using a specific date (like
01-01-0001) to define the date as being empty/Null.

Any thoughts/ideas?

Éric
 
Eric Caron said:
Hi all,

I have a property in one of my classes that represents an optional
date. I'm trying to figure out if I can represent Null or Nothing as
the value for a Date data type. Branching in the data access layer
to send a Null to the stored procedure is no problem, but managing a
Null date in the business object is another matter. I'm thinking of
using a specific date (like 01-01-0001) to define the date as being
empty/Null.

Any thoughts/ideas?

3 thoughts:
- specific date
- property type: object
- wrapped date class

The latter:
class WrappedDate
public Value as Date
public sub new(byval value as date)
me.value = value
end sub
end class

Define the property as WrappedDate. Now the value can be Nothing which would
represent DBNull.


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
* "Eric Caron said:
I have a property in one of my classes that represents an optional date.
I'm trying to figure out if I can represent Null or Nothing as the value for
a Date data type. Branching in the data access layer to send a Null to the
stored procedure is no problem, but managing a Null date in the business
object is another matter. I'm thinking of using a specific date (like
01-01-0001) to define the date as being empty/Null.

You may want to use 'System.Data.SqlTypes.SqlDateTime'.
 
Thank you Armin, that's a very clever way to manage it. I was hoping to get
away with this problem more easily, but I think I can't. Besides, your
method is more elegant than using a specific date.

Thanks again!
 
Back
Top