Temporary Value Error During Entity Framework Core Modify

This exception can also happen if you try to add an entity with a foreign key that does not exists.


Try

    public UserData Update(UserData updatedUser)
    {
        var entity = db.Users.Attach(updatedUser);
        entity.Entry(updatedUser).State = EntityState.Modified;
        entity.SaveChanges(); 
        return updatedUser;
    }

If not worked for you then kindly share your Page.cshtml.

You might be changing the primary key value while updating the row


This "Temporary Value Error During Entity Framework Core Modify" Happens when ID does not arrive at the Update Method.

Problem is not in the code. The problem is in the view you haven't attached it here but look for the following things in your "VIEW".

  1. Make sure the "ID" property exists in the form.
  2. If it exists, then check if you have disabled it? if yes don't disable it. it won't pass the data when you post it.
  3. (If ID is primary key) Make sure ID arrives at the Update method safely without being changed.