RejectChanges Bug


The following snippet does not run correctly:
        OrderCollection Orders = _Dal.GetAllOrders();
        if (Orders.Count == 0) return;
        Order order = Orders[0];
        Customer customer = new Customer();
        System.Diagnostics.Debug.WriteLine("before rejectchanges order.Customers.Count " + order.Customers.Count);
        System.Diagnostics.Debug.WriteLine("after rejectchanges order.Customers.Count " + Orders[0].Customers.Count);
Before the RejectChanges the order.Customers.Count = 1
After the RejectChanges the order.Customers.Count = 1


raffaeler wrote Jun 17, 2007 at 9:20 PM

What behaviour would you like?

The problem is that OrderCollection and all the Order instances has not changed at all.

When you access the order.Customers, you "get" the customer collection and then you add an item in that collection

Reverting the changes on orders cannot revert changes in the customer collection too.


A solution would be to examine (with reflection) all the properties of the order object and invoking, if supported, the IRevertibleChangeTracking.RejectChanges on all the properties.

But this solution is:
  • very slow on all the objects
  • doesn't guarantee that the sub-object is changed in any other way.

So, just for public discussion, what behaviour would you like?

caldarola wrote Jan 24, 2008 at 10:36 AM

The my idea is using RafCollection how it were a DataTable. I have already implemented IRevertibleChangeTracking and IEditableObject on earlier version of RafCollection (1.1).

If Order already implements IRevertibleChangeTracking then rafCollection.RejectChanges() can loop on current items and call order.RejectChanges(). The real question is managing use cases like pending new items, previous removed items, edited items, and so on... when RejectCganges is called.