title: MVC4 data annotation validation based on different user roles using entity framework poco's
body: <p>I'm developing a complex application with about 90 different forms (yeah, awesome).  How do I go about doing complex field validation based on a few requirements:</p>
  
  <p>1) field requirements are based on which user is logged in (role)
  2) field requirements change if other data fields are answered differently (dynamic)</p>
  
  <p>how is this accomplished in MVC4 using EF5 POCO's?</p>
  
  <p>I currently have created data annotations for required fields like so:</p>
  
  <p><strong>My EF5 POCO Model</strong>:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel.DataAnnotations;
  
  [MetadataType(typeof(User_Validation))]
  public partial class User
  {    
      public int UserID { get; set; }
      public string UserName { get; set; }
      public string FirstName { get; set; }
      public string LastName { get; set; }
      public string Password { get; set; }
      public string Email { get; set; }
  }
  </code></pre>
  
  <p><strong>ValidationModels.cs file located with my EF5 POCO's</strong>:</p>
  
  <pre><code>    public class User_Validation
      {    
          public int UserID { get; set; }
  
          [Required(ErrorMessage = "The UserName is required")]
          public string UserName { get; set; }
  
          [Required(ErrorMessage = "The FirstName is required")]
          public string FirstName { get; set; }
  
          [Required(ErrorMessage = "The LastName is required")]
          [Display(Name="Last Name")]
          public string LastName { get; set; }
  
          [Required(ErrorMessage = "The Password is required")]
          [DataType(DataType.Password)]
          public string Password { get; set; }
  
          [Required(ErrorMessage = "The Email is required")]
          [DataType(DataType.EmailAddress)]
          public string Email { get; set; }
      }
  </code></pre>
  
  <p>This works fine and dandy, but how do I make my validations dynamic??</p>
  
  <p>Thanks!</p>