I'm peforming validation using DataAnnotations and Validation Attributes. I'm using ADO NET Entity Model, Domain Services, RIA Services, Silverlight and my projet has a server side that's in ASP .NET.
I want to perform cross-table validation, how can I access the Entity tables from the CustomValidation method.
Let explain with an example.
Suppose I want to avoid two equally named Companies in my data.
(I'm editing the question because I don't know how to response to added comments. IT'S NOT WHAT I NEED ACTUALLY, I JUST WANT TO ACCESS DATA FROM THE CUSTOM VALIDATION METHOD THAT IS LOCATED IN THE SERVER SIDE OF MY APPLICATION.)
I decorate:
[CustomValidation(typeof(CustomValidatorType), "CompanyNameValidation")]
public string CustomerName { get; set; }
Then my CustomValidatorType would be:
public static class CustomValidatorType {
public static ValidationResult CompanyNameValidation(string companyName,
ValidationContext validationContext) {
// How can I see if companyName is already present in Customers entity table?
if (*Company name already exists*) {
// How can I access the Customer Entity Table to check the Company Name existence?
return new ValidationResult("Comapny already exists.", new[] { "CustomerName" });
}
else
return ValidationResult.Success;
}
}
Thank you in advance
My best regards
Rafael