psandler wrote:
All,
Looking for ideas on how to do something like the following generically, but with related entities in addition to fields:
EmployeesEntity employee = new EmployeesEntity();
employee.SaveFields("save");
employee.Orders.Add(new OrdersEntity());
employee.RollbackFields("save");
And have employee.Orders.Count = 0 afterwards.
What I want to do is this:
- User edits (or creates) an entity and clicks "save"
- The entity gets passed to a save routine, which based on a number of things (type of entity, whether it's new or exists in the database) adds additional entities to the graph
- The routine attempts to save the entity recursively
- If there is an exception, the entity gets rolled back to its original state, with the additional entities removed from the graph
Any ideas on how I might accomplish something like this?
Thanks,
Phil
I did this, but it wasn't easy
To do this, I changed the entitycollection code so that it can save different states of itself just like the fields object can. That includes keeping state snapshots of both the .Items in the collection as well as in the removedentitiestracker. If a rollback is requested, the whole graph can roll itself back to a state using the fields rollbacks in addition to the entitycollection rollbacks.