TypeConversionValidator with Nullable

Topics: Validation Application Block
Aug 20, 2007 at 5:59 PM
I'm using VAB with WCF. My DataContract has an optional string field that will eventually be stored in an int database column. I'm not allowed to change the datatype of the field in the contract. The goal is to allow nulls but if the string is not null, it must convert to an int. I tried [TypeConversionValidator(typeof(int?))] but that doesn't work.

Does anyone know if this behavior is supported?

Thanks,
Dave
Aug 21, 2007 at 3:39 PM
Hi Dave,

Can you explain what you mean by doesn't work? You don't get the behavior you expect or you get a runtime error?

The standard mechanism to allow nulls is to use the IgnoreNullsAttribute; if this attribute is present then validation will only occur if the value to validate is not null.

Regards,
Fernando
Aug 21, 2007 at 9:01 PM
Thanks Fernando. I didn't see the IgnoreNullsAttribute. It works as expected.