Delete Child object.

Delete Child object.

Old forum URL: forums.lhotka.net/forums/t/5587.aspx


eloew posted on Tuesday, October 14, 2008

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.

RockfordLhotka replied on Tuesday, October 14, 2008

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();
}

 

Aver replied on Thursday, September 17, 2009

Does this still work in versions 3.5 and newer? I am using 3.7 and I have the same scenario a child object that is not in a collection, but I cannot for the life of me get the object to delete.

Copyright (c) Marimer LLC