Page 1 of 1

Nullable string with length validation issue

Posted: Tue 29 Oct 2013 05:59
by andrei.sbarnea
Configuration: Entity developer - entity framework - dbcontext

A Nullable string with length validation will trigger validation errors if the string is null. Our intention is to apply the length validation only if the field is not null, leaving the possibility for the field to be null. Is this possible ?

Also, how could we check only for max length without checking for min length ?

Re: Nullable string with length validation issue

Posted: Thu 31 Oct 2013 15:10
by Shalex
andrei.sbarnea wrote:A Nullable string with length validation will trigger validation errors if the string is null.
Please set Nullable=True for the corresponding field in both (CSDL and SSDL) parts of the model. If this doesn't help, send us a small test project so that we can reproduce the issue in our environment.

Re: Nullable string with length validation issue

Posted: Fri 22 Nov 2013 07:06
by andrei.sbarnea
Nullable is set in both places.
I think the issue is similar to: http://forums.devart.com/viewtopic.php?f=1&t=27430
only that we are using MySQL and enterprise validation block.

In this particular case the attribute added to the field is:
[Microsoft.Practices.EnterpriseLibrary.Validation.Validators.StringLengthValidator(0, Microsoft.Practices.EnterpriseLibrary.Validation.Validators.RangeBoundaryType.Ignore, 255, Microsoft.Practices.EnterpriseLibrary.Validation.Validators.RangeBoundaryType.Inclusive)]
[System.Runtime.Serialization.DataMember]
public virtual string TheProperty {
...
}

Re: Nullable string with length validation issue

Posted: Sun 24 Nov 2013 10:37
by andrei.sbarnea
Composite validators are not supported with enterprise library attributes.
Therefore both logic methods with: IgnoreNulls or CompositeValidator(.Or) will not work. I modified the template and confirmed this by getting not a valid value validator exception for both of them.
The only workaround that I could find (to keep using attributes) is to introduce nullable support through wrappers over the actual used value attributes.
For example: StringLengthValidator(original arguments) becomes NullableStringLengthValidator(bool nullable, original arguments), and DoValidate method take in account "nullable" and does not log validation errors if (nullable && objectToValidate == null).

Re: Nullable string with length validation issue

Posted: Mon 25 Nov 2013 16:31
by Shalex
This behaviour is caused by Microsoft's StringLengthValidator attribute, so we cannot change it.

From our point of view, you have implemented a correct workaround by using a custom attribute. You can add this attribute to your model in the following way: navigate to Model > Settings > Attributes > select the assembly with your custom attribute and select the attribute in the window below, press OK. The corresponding attribute should be available now in the Attributes menu of the class property.

Re: Nullable string with length validation issue

Posted: Mon 27 Jan 2014 07:39
by andrei.sbarnea
We know of this approach but for us is better to just modify the template. It would be nice that such attributes would be selectable in property edit window and viewable directly in the properties panel, it is not of much use that the panel shows a collection of attributes - in order to check assigned attributes the user needs to do too many clicks per property to get to the actual listing, not productive at all.

Re: Nullable string with length validation issue

Posted: Mon 27 Jan 2014 17:12
by Shalex
Thank you for your feedback. Please suggest your idea at http://devart.uservoice.com/forums/3867 ... -developer.