I understand that LLBLGen does not recursively delete related entities and it is up to the developer to take advantage of AddDeleteEntitiesDirectlyCall for recursive entity deletes. I have gone the route of creating methods such as this:
public void DeleteSomeEntity(int entityID)
{
SomeEntity entity = new SomeEntity(entityID);
UnitOfWork2 uow = new UnitOfWork2();
// Delete children of SomeEntity
uow.AddDeleteEntitiesDirectlyCall("ChildEntity", entity.GetRelationInfoChild());
// Delete SomeEntity
uow.AddDeleteEntitiesDirectlyCall("SomeEntity", new RelationPredicateBucket(SomeEntityFields.ID == entityID));
// Delete potential orphan records that SomeEntity referred to
// The predicate should be based on some info that was retrieved prior to SomeEntity's deletion
uow.AddDeleteEntitiesDirectlyCall("OrphanedEntity", SomePredicate);
uow.Commit(DataAdapter, true);
}
As you can see, the recursive delete is transaction, with additional actions happening before and after deleting the actual desired record. This function is easy to call from, say, a button click, but what about when LLBLGenProDataSource2 is processing SomeEntity deletes from a grid? What is the best way to instruct the data source to use my delete method? Currently I would add the following to the PerformWork event (prior to the commit):
foreach (UnitOfWorkElement2 element in e.Uow.GetEntityElementsToDelete())
{
SomeEntity entity = element.Entity as SomeEntity;
e.Uow.RemoveFromUoW(entity);
DeleteSomeEntity(entity.ID);
}
Is there some centralized way to wire up and always run the specified recursive delete method when an entity needs to be deleted, without having to intercept the GetEntityElementsToDelete() in the data source event?
Hope this makes sense - thanks!