oops I wasn't the sharpest when I wrote my reply friday morning it seems. To delete entities in a collection you indeed need to call AddCollectionForDelete
...
However that's not going to recurse to 1:n related entities (as these aren't in the collection). The 'easiest' is to add a cascade rule to the FK pointing from ChildDetail to Child and specify Delete, so any row deleted from Child will trigger a delete of all related rows in ChildDetail. If other rows in other tables point to ChildDetail then you might want to do the same to the FKs in those tables. This is 'set and forget' but it does require an additional rule to the FK constraint which you have to add to the production database as well.
Another way to do this is to call AddDeleteMultiCall to the uow for the deletion of all ChildDetail rows which point to one of the Child entities in the tracker collection. To do that you need to specify an IN predicate (so you get a DELETE FROM ChildDetail WHERE Pkfield IN (.... ) query) which is constructed using a FieldCompareRangePredicate and you specify the pk values of all Child entities in the tracker collection for the range. You could use the QuerySpec .In(arrayOfValues)
extension method to produce that easily. To get the range of values you could use a linq query e.g. RereadFirst.Child.RemovedEntitiesTracker.Select(Function(f) f.PkField).ToList()
(I hope I wrote the right VB.NET syntax)
What's important here is that you specify DeletesPerformedDirectly
in the commit order before Delete. By default DeletesPerformedDirectly are scheduled after normal deletes which would be too late as you first have to delete the childdetail entities. To do so you can specify the right commit order in the constructor of the unit of work, or alter the collection you get back from the CommitOrder property. The order by default is:
UnitOfWorkBlockType.Inserts
UnitOfWorkBlockType.InsertsPerformedDirectly
UnitOfWorkBlockType.Updates
UnitOfWorkBlockType.UpdatesPerformedDirectly
UnitOfWorkBlockType.Deletes
UnitOfWorkBlockType.DeletesPerformedDirectly