daelmo wrote:
Is that field Nullable?
No.
daelmo wrote:
LLBLGen Pro build version and runtime library version?
LLBLGen Pro Version 2.0.0.0 Final (November 6th, 2006)
Runtime File Version = 2.0.0.61107
I apologize for not originally including that information. I didn't include it in my original message because I didn't think my question was specific to an issue in a particular version.
daelmo wrote:
You could use LLBLGen Pro Validation to avoid send the entity to the persistence storage if there are errors.
Yes, that is what I am doing.
So I'm trying to figure out what triggered the database to return an error about inserting a null value into a database field that doesn't allow nulls.
At first I was going to check if the field is null:
if ( entity.SomeIntField == null )
{
// error
}
But then I realized that it is just a regular int and would never be null.
Then I tried something like this:
if ( entity.Fields["SomeIntField"].IsNull )
{
// error
}
But then I realized that is really for use with database fields that DO allow nulls. But my database field doesn't allow nulls.
Since I saw that the int field was being initialized to zero, I thought I could check if it was still zero before I save:
if ( entity.SomeIntField == 0 )
{
// error
}
I figured if it was still zero, then it wasn't set and therefore it would be an error. In my particular case, that would work because this field happened to be a foreign key field. But then I got to thinking, what if I had a situation where I had a a non-null int field where zero is a valid value?
I was curious if the zero value was the trigger that caused the database error about entering nulls in a non-nullable database field. So I explicitly set the field to zero and I no longer got the database null error. So now I knew that something else was triggering the database null error. Something in LLBLGen knew that the field had not been set and therefore it was trying to assign a null value to the database field.
So I was looking for something in LLBLGen that would tell me whether a field had been set. I am wondering if the IsChanged property is the thing to use:
if (!entity.Fields["SomeIntField"].IsChanged )
{
// error
}
Or should I be using some other method to determine if a field has been set?