I have a Parent object (editable root) that contains one child object(editable child). When I call delete on the child object I get the error "Can not directly mark a child object for deletion - use its parent collection". My problem is that this child object is not in a collection since there is only one. It is just an object of the parent. How can I delete this child?
Thanks.
I don't remember when this interface was added off the top of my head. But your parent object can cast the child as IEditableBusinessObject and call the DeleteChild() method on that interface.
You'd probably do this in some RemoveChild() method in the parent. So if the parent is a Product object that has a PrimaryVendor property (child object), you might do this in Product:
public void RemovePrimaryVendor()
{
var vendor = ReadProperty(PrimaryVendorProperty);
if (vendor != null)
((IEditableBusinessObject)vendor).DeleteChild();
}
Copyright (c) Marimer LLC