Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RejectChanges for specific Entities

I'm having the following issue with WCF RIA Services: I have a table Customer and a table Address. A customer can have 0...n addresses. There is a form for editing the customer, with a Datagrid that displays the addresses. You add / edit an address in a child window by clicking Add / Edit. Now here's the thing:

The problem is that the user should always be able to cancel edits. This is not a problem except: If you create a new customer and you add an address to that customer, then want to edit the address but want to cancel that edit.

  • You can't do RejectChanges to the context, because it would erase the address with the customer.
  • You can't use seperate contexts because then you can't establish the foreign key relation.

How would you guys solve that?

like image 560
LueTm Avatar asked Aug 21 '11 10:08

LueTm


1 Answers

Entity implements IRevertibleChangeTracking to support this scenario. Since it's implemented explicitly, you'll have to cast it. The following code will work.

((IRevertibleChangeTracking)address).RejectChanges();
like image 145
Kyle McClellan Avatar answered Oct 22 '22 04:10

Kyle McClellan