Nullable Types before C# 2.0
I ran into the Nullable Types project a week ago and it's a pity I don't have the time to play with it. There were so many times I wished I could do something semantically equivalent to setting and checking for emptiness of value types. For example, when I designed a simple ORM for my first .NET project I had trouble representing DB NULLs as values of strongly typed members. There is no simple way to do so...
How can I represent empty int, double ot DateTime? Well, numbers can be 0 or -1. For DateTime I ended up using DateTime.MinDate. But in my current project when I accidently tried to write DateTime.MinDate in MS SQL I got an exception, since MS SQL only supports dates between 1/1/1753 and 31/12/9999. Eric has more clever solution for DateTime emptiness, I really like the simplicity and power of such approach.
The way strongly-typed DataSets deal with NULLs is OK but seems a bit artificial. Values are not stored as strongly typed but are boxed when accessed through the properties. It is a bit awkward to call functions as IsXNull() and SetXNull().
So, if you are tired of such problems try this link. The online documentation and the FAQ will answer most of your questions.



0 Comments:
Post a Comment
<< Home