I am using NH 1.2.1 with VB.NET 2.0.
I ran into a problem that took me some time to understand. I had a column in the database with a nullable int. It was mapped like this:
Code:
<property name="ColumnName" />
The object loaded fine but an UPDATE was issued even though I had not changed anything. Running some logging i finally realized that I had not declared my property as nullable. It was declared like this (only showing private variable):
Code:
Private _ColumnName As Integer
When I changed it to this the UPDATE did not occur:
Code:
Private _ColumnName As Integer?
What was happening was that the database value was NULL but since the property was not declared as a Nullable type it was set to default value of zero. Then when NH checked for changes it got (0 != NULL) and tried to UPDATE.
Now this is all fine but it is an easy mistake to make and I think it is very dangerous to generate an UPDATE that you may not be aware of.
Because of this I want to enforce the use of Nullable types in the project so if a programmer tries to map a nullable column in the database to a non-nullable valuetype property an exception occures when NH tries to create the object instead of NH silently setting the property to default value and then generating an UPDATE.
Is there anyway to enforce this mapping rule?