title: How to handle System.Data.Entity.Validation.DbEntityValidationException?
body: <p>My app gets the following error:</p>
  <blockquote>
  <p>An exception of type
  'System.Data.Entity.Validation.DbEntityValidationException' occurred
  in EntityFramework.dll but was not handled in user code</p>
  <p>Additional information: Validation failed for one or more entities.
  See 'EntityValidationErrors' property for more details.</p>
  </blockquote>
  <p>I get this error when trying to register a new user. Error happens on 'db.SaveChanges()'</p>
  <p>Here is the code:</p>
  <pre><code>public ActionResult Registration(x.Models.User user)
  {
      if(ModelState.IsValid)
      {
          using(var db = new xDBEntities1())
          {
              var crypto = new SimpleCrypto.PBKDF2();
              var encrpPass = crypto.Compute(user.password);
              var sysUser = db.users.Create();
                      
              sysUser.email = user.email;
              sysUser.username = user.username;
              sysUser.password = encrpPass;
              sysUser.premium_credits = 0;
              sysUser.login_times = 0;
              sysUser.last_ip = Request.ServerVariables[&quot;REMOTE_ADDR&quot;];
              sysUser.creation_ip = Request.ServerVariables[&quot;REMOTE_ADDR&quot;];
              sysUser.banned = 0;
              sysUser.creation_date = DateTime.Now;
              sysUser.creation_time = DateTime.Now.TimeOfDay;
  
              db.users.Add(sysUser);
              db.SaveChanges();
          }
      }
      return RedirectToAction(&quot;Index&quot;, &quot;Home&quot;);
  }
  </code></pre>
  <p>edit:
  User model class</p>
  <pre><code>public class User
  {
      [Required]
      [StringLength(50)]
      [Display(Name=&quot;Username: &quot;)]
      public String username { get; set; }
      [Required]
      [DataType(DataType.Password)]
      [StringLength(50,MinimumLength=6)]
      [Display(Name=&quot;Password: &quot;)]
      public string password { get; set; }
      [Required]
      [EmailAddress]
      [StringLength(50)]
      public string email { get; set; }
      public int phonenumber { get; set; }
      public int mobilephonenumber { get; set; }
  
      }
  }
  </code></pre>
  <p>How can I handle it ?</p>