J
James Fisher
How are people handling NULL values for value types.
Descriptions of problem
Say you have a typical method with the signature:
public int InsertPerson(string firstName, string lastName, int
personCategoryID)
Now say you only want the firstName and lastName parameters to be
required and to retain the NULL value in the database for
personCategoryID. Here are a couple typical solutions for this
scenerio would be:
A. Overload the InsertPerson method and create the following method.
public int InsertPerson(string firstName, string lastName)
So when you detect in your UI that personCategoryID is to be NULL or
"empty" you will call InsertPerson with two parameters. Therefore,
the personCategoryID field in the database will remain NULL.
B. Treat the int as an object and use boxing and unboxing. In my
example convert the int parameter to an object type and check for null
in the method so I can set the stored procedure parameter to DBNull.
My slant on the problem
I happen to have inserts for different types of "People" that have
many (30-40) parameters in their insert methods. So option A above
would not be feasable and option B is more likely however I would have
to modify alot of code to change all my int it objects and use boxing
and unboxing(but certainly feasible). I am interested to hear how
other people are handling this problem.
JF
Descriptions of problem
Say you have a typical method with the signature:
public int InsertPerson(string firstName, string lastName, int
personCategoryID)
Now say you only want the firstName and lastName parameters to be
required and to retain the NULL value in the database for
personCategoryID. Here are a couple typical solutions for this
scenerio would be:
A. Overload the InsertPerson method and create the following method.
public int InsertPerson(string firstName, string lastName)
So when you detect in your UI that personCategoryID is to be NULL or
"empty" you will call InsertPerson with two parameters. Therefore,
the personCategoryID field in the database will remain NULL.
B. Treat the int as an object and use boxing and unboxing. In my
example convert the int parameter to an object type and check for null
in the method so I can set the stored procedure parameter to DBNull.
My slant on the problem
I happen to have inserts for different types of "People" that have
many (30-40) parameters in their insert methods. So option A above
would not be feasable and option B is more likely however I would have
to modify alot of code to change all my int it objects and use boxing
and unboxing(but certainly feasible). I am interested to hear how
other people are handling this problem.
JF