This error is being generated when I try to change a foreign key. I know this is a very common error I’ve found tons of information about it and tried to implement the fixe
I think you are trying to assign an ID when you need to assign the entity. (I'm not 100% sure this is what you are doing)
// Don't assign just the id Person.ParentId = parentId; // Assign the entity Person.Parent = db.Parents.Single(x.Id == parentId);