I'm trying to set up some custom validation methods that use the System.ComponentModel.DataAnnotations. I have written a few generic methods to use for validation. Here is the one where the problem occurs:
private void SetValidationAttributeErrors<TEntity>(TEntity item, List<string> errors)
{
var result = from prop in TypeDescriptor.GetProperties(item).Cast<PropertyDescriptor>()
from attribute in prop.Attributes.OfType<ValidationAttribute>()
where !attribute.IsValid(prop.GetValue(item))
select attribute.FormatErrorMessage(string.Empty);
}
I have an error on the 'ValidationAttribute' type saying that it could not be found. I have the using statement for DataAnnotations. Any ideas?