loonison101
8/7/2015 - 2:28 AM

Update_certain_fields_entity_framework.cs

// From this URL: http://stackoverflow.com/questions/3642371/how-to-update-only-one-field-using-entity-framework
public void ChangePassword(int userId, string password)
{
  var user = new User() { Id = userId, Password = password };
  using (var db = new MyEfContextName())
  {
    db.Users.Attach(user);
    db.Entry(user).Property(x => x.Password).IsModified = true;
    db.SaveChanges();
  }
}