2
Vote

CreateValidatorFromAttributes doesn't use DataAnnotations Attributes

description

<p>this is solved by using ValidationFactory.CreateValidator but it is strange and counter intuitive that ValidationFactory.CreateValidatorFromAttributes</p> <p>doesn&#39;t do this.</p> <p>Is this a bug?</p>

comments

AvanadeSupport wrote Mar 14, 2011 at 3:08 AM

It seems a bug. The DataAnnotation validators for a certain property gets included in the validators if there's another EntLib validator for that property.

ctavares wrote Mar 15, 2011 at 4:20 AM

It was a deliberate choice actually - we didn't want to change the behavior of existing code that uses this method by pulling in the data annotations attributes. We also want to get rid of this method completely. Instead, use one of the overrides that takes a ValidationSpecificationSource.

So you could instead say:

ValidationFactory.CreateValidator(typeof(whatever), ValidationSpecificationSource.Attributes | ValidationSpecificationSource.DataAnnotations);

to get what you want.

(Although I did just find another bug - ValidationSpecificationSource needs to have the Flags attribute on it.)

ctavares wrote Mar 15, 2011 at 4:20 AM

Never mind, it does have the Flags attribute on it. The rest of my comment still stands. :-)