0

Hello I have a UI like this

enter image description here

so What I want to do is: If I press the x button and close the form I want to undo all the changes on this record.

If you take a closer to the UI you can see that there is a another form for the browsing purpose. Both forms use the same context.

so what happens is this. when I close and reopen the same record I get the above UI

below Is how I fill the BindingSource dynamically.

Base4Data = ((dynamic)(IQueryable)Context.GetPropValue(TableName)).Find(MyPkValue);

things I tried on FormClosing event:

1- Setting the current context to a new dbcontext instance on formclose

2- Create new transaction in form handlecreate and rollback transaction on formclose

3- ((IObjectContextAdapter)Context).ObjectContext.Refresh(RefreshMode.StoreWins, Base4Data);

4- Context.Entry(Base4Data).Reload();

non of the above work, so any suggestions are very appreciated

Asım Gündüz
  • 1,257
  • 3
  • 17
  • 42
  • 1
    I think you could get the data out of the database again and therefore overwriting current( with unsaved) data – Ronald Haan May 06 '19 at 11:35
  • 2
    Possible duplicate of [Undo changes in entity framework entities](https://stackoverflow.com/questions/5466677/undo-changes-in-entity-framework-entities) – Tim May 06 '19 at 11:46

0 Answers0