We have a contract entry application that allows users to create, update, and delete entities through a web UI. After a user finishes his/her edits and clicks save, their entry is validated against a set of business rules. If all entities pass validation the structure is saved to the database, if not then the user has to make changes. These entities form a one to many parent-child relationships similar to below. With each entity having navigators, or entity collections, between each other.
Parent Entity - 1:m - Detail Entity - 1:m sub-item.
Additionally, all of the items have foreign keys (and navigators) to reference data tables, with many of the items having keys to the same table. For example, Parent, Detail, and sub-item have foreign keys and navigators to Location and Currency tables.
We’re seeing an issue where if a sub item or detail item is removed by calling .Remove() from its parent entity’s collection, the item still persists in memory. When we call adapter.save with recursive set to true, the sub-item still gets saved. We’ve also tried additionally setting the navigator from the child item to the parent item to null, but we still get the same problem.
From reading other posts, my guess is that when we save recursively, the saves may be going through some of the reference data entities (for example if parent and detail point to the same location entity) and are thus able to arrive at the child record we attempted to remove.
My question then is three parts:
- If a parent and child item both reference the same entity from a third table, would a recursive save from the parent reach the child through said reference entity, even if the parent and child didn’t directly reference each other (I’m guessing the answer to this is yes, but I wanted to do my due diligence).
- If I want to remove an unsaved item completely from the object graph (so that it would not be saved), what are the steps I need to take. Can I simply set all navigators pointing out from the child item to null? Or do I also need to find any entity collections it may have been a part of and remove it from those as well?
- Is there potentially some kind of remove all references method that would take care of some of this for me? or a way to do this generically? There are a significant number of reference tables, and maintaining a procedure that cleaned up references as we add or remove reference data tables is something I would prefer to avoid if I could.
Thanks in advance!
Matt