Here is what I came up with. It's working, but I don't like it.
public static int RemoveOrphanedChildren(IDataAccessAdapter adapter)
{
IRelationPredicateBucket DeleteFilter = new RelationPredicateBucket();
FieldCompareSetPredicate CompareSet = new FieldCompareSetPredicate(
EntityFieldFactory.Create(ChildFieldIndex.ParentId), null,
EntityFieldFactory.Create(ParentChildFieldIndex.ParentId), null,
SetOperator.In, null);
CompareSet.Negate = true;
DeleteFilter.PredicateExpression.Add(CompareSet);
EntityCollection children = new EntityCollection(new ChildEntityFactory());
adapter.FetchEntityCollection(children, DeleteFilter );
return adapter.DeleteEntityCollection(children);
}
I don't like this solution because the ChildEntity has a photo in it, that can be rather large. I'm having to send quite a bit across the wire, just to get the children collection, then to turn around a delete it.
How can I turn this into a straight delete, rather then select first, then delete?
Thanks for the feedback.