Reputation: 49
I’m using Silverlight4 and Ria Service :
Imaging we have a table (called "MyTable") with 3 records ( 1 , 2 , 3 ) , I’ve just written the following codes somewhere in my application:
CurrentItem = 1;
MyContext.MyTables.Delete(CurrentItem);
CurrentItem = 2;
MyContext.MyTables.Delete(CurrentItem);
For some reasons, before hitting The “Save” Button, I want to reject the first deleted item(1) but still want to delete the second one(2) .it means that I can’t use :
MyContext.RejectChanges()
Because It will reject all changes (including the deleted item which what I do want to delete it) so I though, using IRevertibleChangeTracking can solve my issue .Something like this :
((IRevertibleChangeTracking) MyItem).RejectChanges();
But before using this Interface, I have to access the deleted Item. At first, It tried to get it via MyContext.MyTables but it doesn’t contain deleted records so I tried to obtain it by EntityChangeSet:
EntityChangeSet Changes = MyContext.EntityContainer.GetChanges();
MyTable DeletedItem = Changes.First<MyTables>( e => e.ID = 1 ) ;
And then I used IRevertibleChangeTracking:
((IRevertibleChangeTracking) DeletedItem ).RejectChanges();
But after Running, This line of code didn’t change the state of the record and it was kept as “Deleted” so by hitting the “Save” Button, It was deleted from the Database Physically !!!! It seems IRevertibleChangeTracking doesn’t work for deleted/Added items ( it just works for modifed Items ).
So ,Is there any way to reject a particular deleted item from the DomainContext.
Thanks,
Upvotes: 2
Views: 730
Reputation: 896
After a bit more hunting, I found where Colin Blair says:
Every RIA Services entity implements the IRevertibleChangeTracking interface. All you have to do is cast your entity to IRevertibleChangeTracking and call RejectChanges. RejectChanges does not work for new or deleted entities.
Instead of deleting each entity, can you set a boolean property to false, and when finished, delete the entities with the flag set to false
?
Upvotes: 0