I am trying to undo some changes using the reload function. I get an InvalidOperationException . How can I prevent this?
DbContext.SaveChanges(); //Entity is in Unchanged state //Make some changes to an entity //Change state to modified DbContext.Entry(entity).Reload();
InvalidOperationException
EntityMemberChanged or EntityComplexMemberChanged is called without first calling EntityMemberChanging or EntityComplexMemberChanging on the same change tracker with the same property name. For information on proper change reporting, see the Entity Framework documentation.
EDIT:
I turned on and off ProxyCreationEnabled , LazyLoadingEnabled .
We tried other approaches. All these attempts raise the same exception.
var objContext = ((IObjectContextAdapter)context).ObjectContext; objContext.Refresh(RefreshMode.ClientWins, entry.Entity);
entry.OriginalValues.SetValues(entry.GetDatabaseValues());
I hope I get a solution. Do not want to delete the full DbContext in order to reload all the data.
source share