title: Using CustomValidationAttribute with Entity Framework
body: <p>I want to implement some conditional validation logic on one of my entities. Basically, what I want to do is validate a field (using a regular expression) only if another field in my entity has a certain value.</p>
  
  <p>I tried adding a <code>CustomValidationAttribute</code> on my entity but it doesn't do anything</p>
  
  <pre><code>[MetadataType(typeof(TemplateActionMetadata))]
  [CustomValidation(typeof(TemplateAction), "validateActionValue")]
      public partial class TemplateAction 
      {
          public static ValidationResult validateActionValue(string pValue, ValidationContext vContext)
          { //this never gets called
              return ValidationResult.Success;
          }
      }
  </code></pre>
  
  <p>I also tried adding the attribute on my field</p>
  
  <pre><code>public partial class TemplateActionMetadata
      {
  
          [CustomValidation(typeof(TemplateAction), "validateActionValue")]
          public string ActionValue { get; set; }
      }
  </code></pre>
  
  <p>Now it does call the <code>validateActionValue</code> method but the <code>ValidationContext</code> parameter is always null, so I have no way of getting the value of the other field that I need to use to implement my validation logic.</p>