0

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

Rafael
  • 2,413
  • 4
  • 32
  • 54
  • You should definitely create a `Company` table and let `Customer` refer to that. What if two companies are different, but have the same name? Or if two customers have the same company? I'd be surprised if customer <=> company name is 1:1. – Gert Arnold Sep 19 '12 at 15:35
  • " How can I see if companyName is already present in Customers entity table?" Make a call to you database and perform a check. – Forty-Two Sep 19 '12 at 16:09

0 Answers0