Multiple DataAnnotation's attribute bug

Multiple DataAnnotation's attribute bug

Old forum URL: forums.lhotka.net/forums/t/7789.aspx


Regent posted on Thursday, October 15, 2009

A have a property called CatalogNumber defined as:


private static PropertyInfo<string> CatalogNumberProperty = RegisterProperty<string>(p => p.CatalogNumber);
[Required, StringLength(50)]
[Indexable]
public string CatalogNumber
{
get { return GetProperty(CatalogNumberProperty); }
set { SetProperty(CatalogNumberProperty, value); }
}


Later I found that validation work wrong when the same property have more than one ValidationAttribute.

Specifically in this case when I assign p.CatalogNumber = new string('t', 100) it checks according to ValidationRules.CheckRules(List<IRuleMethod> list)
1. StringLengthAttribute - will add broken rule named 'rule://Csla.Validation.CommonRules/DataAnnotation/CatalogNumber';
2. RequiredAttribute - will clear broken rule named 'rule://Csla.Validation.CommonRules/DataAnnotation/CatalogNumber'

So the problem is that all DataAnnotation rules have the same name for the same property.

I recommend to add attribute's type name, like 'rule://Csla.Validation.CommonRules/DataAnnotation/CatalogNumber?RequiredAttribute'

Copyright (c) Marimer LLC