G'day all,
This is both a general request for 'best-practise' devforce design, and also a specific question about my current scenario.
How would you recommend devforce be used/managed to support user-cancellation of complex edits?
In our app as currently designed, we have a small, fixed number of EntityManager's that are created and loaded with cached reference data at application startup. When a user requests an edit we load the required item, Include()'ing the relevant child data, and relying on the cached reference data to auto-attach those entities.... this works perfectly!
If the user makes some changes to the item (I'll talk a normal Order -> OrderDetails scenario), say changing an orderdate, and then chooses to cancel their edit, we call the RejectChanges() method, and the date rolls back exactly as expected.
However we run into problems with adding new child items (eg, an OrderDetail), and then cancelling changes.... these items seem to remain in the EntityCache or similar in a detached state, with their generated -100 id. This causes problems if we (for example):
1. Pop a new Order/OrderDetails set of data
2. Cancel Changes
3. Make some other save that resets the generated ID's back to -100
4. Another pop of a new item results in the earlier OrderDetails magically coming back to life and attaching themselves to the new Order. Other symptoms include errors regarding multiple items with the same (-100 based) ID as the id's are recycled after the save.
We've been playing with specifically removing items from the EntityManager after rejecting the changes eg:
_cxt.RejectChanges; //Model state goes from Added to Detached
if (Model.EntityState == EntityState.Detached) //was freshly added until we cancelled
{
Model.EntityAspect.RemoveFromManager(true); //Remove from the cache, don't try and save it later on
}
And this has definately reduced the number of issues we're seeing, but it isn't sufficient for all our scenarios (hence the general request for your recommended approach above).
If I can provide any more info please just ask.
Cheers,
Tim