G
Guest
In Java, creating a class that represents a tuple in a database is relatively
simple because if you have a field for, lets say, "Quantity" that is an
integer, you can set it to null. Since .NET uses a stack for these Value
Types, the integer (Int32) has an initial value of 0 and you can't set it to
null.
So, what's the best way to approach this without having to jump through a
bunch of programmatic hoops? These are a couple of ways I've though of.
1) Create a constant that represents a null Int32, et and use that value
(problem: you'd have to constantly check that value if you're doing
calculations)
2) Make all of your properties be objects. That way you could set the
property to an integer, or a null (or DBNull.Value). (problem: performance
hit from boxing and potential errors when doing calculations)
3) Have a property for the field and then have an ancillary property names
"FieldXIsNull" (problem: classes get bulky and you end up having to check
the IsNull constantly)
So, what are the best ways to approach this?
Side Note, I'd like to stay away from using datasets because they're big
memory hogs. If I can have a class that I can instantiate that keeps track
of real values, I'll get better memory usage. As far as the overhead of
coding all of these classes, I can use/create code generators for that.
simple because if you have a field for, lets say, "Quantity" that is an
integer, you can set it to null. Since .NET uses a stack for these Value
Types, the integer (Int32) has an initial value of 0 and you can't set it to
null.
So, what's the best way to approach this without having to jump through a
bunch of programmatic hoops? These are a couple of ways I've though of.
1) Create a constant that represents a null Int32, et and use that value
(problem: you'd have to constantly check that value if you're doing
calculations)
2) Make all of your properties be objects. That way you could set the
property to an integer, or a null (or DBNull.Value). (problem: performance
hit from boxing and potential errors when doing calculations)
3) Have a property for the field and then have an ancillary property names
"FieldXIsNull" (problem: classes get bulky and you end up having to check
the IsNull constantly)
So, what are the best ways to approach this?
Side Note, I'd like to stay away from using datasets because they're big
memory hogs. If I can have a class that I can instantiate that keeps track
of real values, I'll get better memory usage. As far as the overhead of
coding all of these classes, I can use/create code generators for that.