Hi gurus, i have a Customer class which includes a Contact class that stores all the contacts for that particular customer, so they are linked with a foreign key relationship.
Here is my scenario: the user Edits the customer's info including the contacts, and then decides to hit the "Cancel" button. The contacts are bound to a grid so everytime an edit/add/delete is made it automatically updates the Contact entity in the cached database context. So how can i rollback all the changes made by the user to the Contact entity?
I tried the following (after searching google for answers):
public static void CustomerRollback(Customer customer)
{
dbContext.Refresh(System.Data.Objects.RefreshMode.StoreWins, customer);
dbContext.Refresh(System.Data.Objects.RefreshMode.StoreWins, customer.Contacts);
}
But that didn't work. Any other ideas? Please note that my problem is only with rolling back the Contacts entity. I guess what's causing the issue in the first place is that the grid automatically updates the cached entities. So when i try to cancel, the EntityState for each contact has already changed to a modified state (EntityState.Added, EntityState.Deleted, etc.). Do i need to loop through the contacts and check their EntityState property and do something with it?
Thanks Caesar