Problems with validating a new entity

Posts   
 
    
Jeff M
User
Posts: 250
Joined: 04-Aug-2004
# Posted on: 17-Jan-2005 19:57:19   

Lets say that I have an entity with a string field and an int32 field. The int32 field contains the FK of a related table. Both are required fields.

Testing the validity of the string field is easy: entity.StringField.ToString().Trim() would trigger a validation error.

Testing the int32 field is not so easy: The DBValue is null (because it's a new entity) but you can't test for DBValue because entering a value into entity.IntField doesn't change entity.IntField.DBValue - - it's STILL null. Therefore, testing for null (by using DBValue or TestOriginalFieldValueForNull) doesn't help in this validation scenario because you'd get an inaccurate TRUE value if you'd made an entry into the entity.IntField. We could test for TypeDefaultValue.GetDefaultValue - - but that doesn't work either, because the default valueToReturn for System.Int32 is 0, which MIGHT be considered a valid entry.

So, I can't seem to figure this problem out.

Does anyone have some ideas on this?

Thanks. Jeff

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 17-Jan-2005 20:54:57   

DbValue is the value read from the db. CurrentValue is the value of the field in memory. If you want to validate the value of the field as it is set in memory, verify the CurrentValue. If you want to validate against the DB value, compare DbValue with CurrentValue etc.

Is this the scenario you want to use it in? Is there a reason you have to use dbvalue and not currentvalue?

Btw: if a field's IsChanged flag is false, the field isn't changed, so the value you read from CurrentValue is undefined.

Frans Bouma | Lead developer LLBLGen Pro
Jeff M
User
Posts: 250
Joined: 04-Aug-2004
# Posted on: 17-Jan-2005 21:14:04   

Yes, thanks. CurrentValue seems to work.

Jeff