title: Entity framework DbEntityValidationException- could not find the entity
body: <p>I want to post the data from my register form to my database.At first i had a very common error "the entity type <code>&lt;model&gt;</code> is not part of the model for the current context". I solve it and then another error appeared. So now the error that appeared was in the SaveChanges section and it is "could not found the entity Password". How can I fix that?</p>
  
  <p><strong>Here is the code of my context.</strong></p>
  
  <pre><code>public partial class MyDbEntities : DbContext
  {
      public MyDbEntities()
          : base("name=MyDbEntities")
      {
      }
  
      protected override void OnModelCreating(DbModelBuilder modelBuilder)
      {
          modelBuilder.Entity&lt;User&gt;().ToTable("Users");
          modelBuilder.Entity&lt;User&gt;().Property(u =&gt; u.Name).IsRequired().HasMaxLength(256);
          modelBuilder.Entity&lt;User&gt;().Property(u =&gt; u.Surname).IsRequired().HasMaxLength(256);
          modelBuilder.Entity&lt;User&gt;().Property(u =&gt; u.Email).IsRequired().HasMaxLength(200);
          modelBuilder.Entity&lt;User&gt;().Property(u =&gt; u.password).IsRequired().HasMaxLength(100);
          modelBuilder.Entity&lt;User&gt;().Property(u =&gt; u.address).IsRequired();
          modelBuilder.Entity&lt;User&gt;().Property(u =&gt; u.postcode).IsRequired();
          modelBuilder.Entity&lt;User&gt;().Property(u =&gt; u.number).IsRequired();
  
      }
      public override int SaveChanges()
      {
          try
          {
              return base.SaveChanges();
          }
          catch (DbEntityValidationException ex)
          {
              string errorMessages = string.Join("; ", ex.EntityValidationErrors.SelectMany(x =&gt; x.ValidationErrors).Select(x =&gt; x.ErrorMessage));
              throw new DbEntityValidationException(errorMessages);
          }
      }
  
      public virtual DbSet&lt;User&gt; Users { get; set; }
  }
  </code></pre>
  
  <p><strong>And here is the code of my controller</strong></p>
  
  <pre><code>  [HttpPost]
      [ValidateAntiForgeryToken]
      public ActionResult Register(User U)
      {
          using(MyDbEntities db=new MyDbEntities())
          {
              db.Users.Add(U);
              db.SaveChanges();
              ModelState.Clear();
              U = null;
              ViewBag.Message("Seccesfully stored");
          }
          return View(U);
      }
  </code></pre>
  
  <p><strong>And the model</strong>
  ` </p>
  
  <pre><code>        [Required]
          [Display(Name = "Name")]
          public string Name { get; set; }
  
          [Required]
          [Display(Name = "Surname")]
          public string Surname { get; set; }
  
  
          [Required]
          [Display(Name = "Email")]
          public string Email { get; set; }
  
          [Required]
          [DataType (DataType.Password)]
          [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
          [Display(Name = "Password")]
          public string password { get; set; }
  
  
          [Required]
         [DataType(DataType.Password)]
          [Display(Name = "Confirm Password")]
          [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
          public string ConfirmPassword { get; set; }
  
  
          [Required]
          [Display(Name = "Address")]
          public string address { get; set; }
  
          [Required]
          [Display(Name = "PostVode")]
          [DataType(DataType.PostalCode)]
          public string postcode { get; set; }
  
          [Required]
          [Display(Name = "Phone Number")]
          public string number { get; set; }
  </code></pre>