I decided to create a method named "DeleteWithChildren()" that will take the primary key id of the parent entity to follow the same controller pattern already in place similar methods.
DeleteWithChildren() will go load the parent entity using the primary key and then invoke the corresponding controller class for each of each children.
For example,
public void DeleteWithChildren(object keyID)
{
// Load the entity
MyCompany.Model.Employee entity = new MyCompany.Model.Employee(keyID);
foreach(MyCompany.Model.SiteEmployee child in entity.SiteEmployeeRecords)
{
MyCompany.Controller.SiteEmployeeCtrl.Instance.DeleteWithChildren(child.SiteEmployeeId);
}
}
This allowed me to simple invoke the parent entity controller such as Controller.ParentEntity.DeleteWithChildren(5000); and have the controller delete everything the hangs off the ParentEntity object by calling the DeleteWithChildren() method for each child. This allows to delete hierarchical entities.
You can download the template file from my online box here.
My template was code to first check that a transaction was started since you might not want to attempt to delete everything from that entity without a transaction.
No comments:
Post a Comment