473,385 Members | 1,912 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Object Models and NULL

I posted this a couple of days ago, but it was buried with another question.

How do people deal with NULL values in an object model?

Consider the following example often used. I can't see anyway to indicate
an age is undefined. So if I get a null from the database what do I store
here and when placing it on the screen, how do I know to put nothing (as
opposed to 0). Is there a methodology people use? Null indicator variable,
Nullable type, etc. Do I just write compound if statements to test and
determine what to use everywhere? Seems like a very common problem many
other people must be solving in fashion.

Public Class Customer
Private _age As Integer
Public Property Age() As Integer
Get
Return _age
End Get
Set(ByVal value As Integer)
_age = value
End Set
End Property
End Class
Apr 11 '06 #1
1 952
Nullable types in 2.0, which are a real let down in the fundamental mapping
way, is the best way to deal with the problem.

It's total crap that you can't assign DbNull.Value to a nullable type nad
have it just work. You still need to if value is DbNull.Value in your
mapping layer (both ways), but alteast once that's done, you have access to
x.HasValue for all primitive types (int/bools/blahs)

Assuming you can't move to 2.0...there's no magic solution. On approach is
to not allow nulls for those fields in your database - which makes the
mapping process a lot easier, but isn't practical in all cases. I've used
things like constants assigned to Int32.MinValue - which is a majob problem
waiting to happen.

Just some thoughts :)

Karl

--
http://www.openmymind.net/
http://www.fuelindustries.com/
"Larry Charlton" <La***********@discussions.microsoft.com> wrote in message
news:B5**********************************@microsof t.com...
I posted this a couple of days ago, but it was buried with another
question.

How do people deal with NULL values in an object model?

Consider the following example often used. I can't see anyway to indicate
an age is undefined. So if I get a null from the database what do I store
here and when placing it on the screen, how do I know to put nothing (as
opposed to 0). Is there a methodology people use? Null indicator
variable,
Nullable type, etc. Do I just write compound if statements to test and
determine what to use everywhere? Seems like a very common problem many
other people must be solving in fashion.

Public Class Customer
Private _age As Integer
Public Property Age() As Integer
Get
Return _age
End Get
Set(ByVal value As Integer)
_age = value
End Set
End Property
End Class

Apr 11 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: mikeyjudkins | last post by:
Ive been banging my head on the wall for hours with this one, hopefully someone will know what Im doing wrong here :\ The Goal: I have an xml file that is generated on the fly via JSP which I...
16
by: sneill | last post by:
How is it possible to take the value of a variable (in this case, MODE_CREATE, MODE_UPDATE, etc) and use that as an object property name? In the following example I want 'oIcon' object to have...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.