My code looks like this: (where "user" is the UserProfile instance passed back from the view after being edited)
UserProfile original = DBContext.UserProfiles.Where(x => x.UserId == user.UserId).FirstOrDefault();
if (original != null)
{
original = user;
DAL.DAL.Instance.TGIMobiledb.SaveChanges();
}
This code fires without error, but does not update the DB. After some research it seems I have to add the following line before calling SaveChanges()
DBContext.Entry(original).State = EntityState.Modified;
But that line of code causes this error:
"An object with the same key already exists in the ObjectStateManager. The ObjectStateManager cannot track multiple objects with the same key."
The changes saves to the db fine if I assign every field manually like this:
original.UserId = user.UserId;
original.FirstName = user.FirstName;
original.Surname = user.Surname;
original.UserName = user.UserName;
Obviously this is less than optimal, especially with the larger entities.