*** This is fixed. ***
When deleting related objects (such as addresses, contacts for an agency), what's the best way of doing this? There's no direct relation (on the database) between the parent and child, as the addresses and contacts could contain records for other entities such as clients, organizations, etc. They are tied to each other by an EntityId column of type Guid, so it's unique, and DevForce has this mapping as well to load the related records.
What I'm doing in the Delete method is creating an EntityList<Entity>, recursing through the contacts and addresses objects of the item being deleted, adding them to the EntityList and calling the delete function on them. Then I add the Agency object to the list, call it's Delete function, and call the Save method on the PersistenceManager passing the EntityList to it. Is this the best (or only) way? I've included the Delete function below.
public static void Delete(Agency agency) { EntityList<Entity> changedEntities = new EntityList<Entity>(); foreach(Contact contact in agency.Contacts) { changedEntities.Add(contact); contact.Delete(); }
foreach(Note note in agency.Notes) { changedEntities.Add(note); note.Delete(); }
foreach(AgencyClients agencyclient in agency.Clients) { changedEntities.Add(agencyclient); agencyclient.Delete(); }
foreach(Address address in agency.Addresses) { changedEntities.Add(address); address.Delete(); }
changedEntities.Add(agency); agency.Delete(); mPersManager.SaveChanges(changedEntities); }
|
Thanks,
Julian
Edited by JulianBenjamin - 01-Sep-2007 at 9:41pm