OnAfterUpdate works, I have updated the code below. Ok, so that eliminates the loop issue. But there is still the issue of duplicating the children. The aim of the new property "OdataChildren" is to act as an exact copy of the "Children" property. They have to be in synch at all times, when children are added/removed and when child nodes change position (child node is moved up or down). The solution below is to clear all the contents of OdataChildren and then iterate through all the children and add each of them to OdataChildren. This might become a very heavy job as the number of children increases. So I was wondering if there is a better way to keep two relations in synch?
The only purpose for this is to expose the children in the OData feed. As far as I know this is the only way to do that without exposing the children of the other Hierarchical nodes.
public override void OnAfterUpdate()
{
base.OnAfterUpdate();
UpdateOdataChildren();
}
protected void UpdateOdataChildren()
{
this.OdataChildren.RemoveAll();
var children = this.Children.Get();
foreach (var child in children)
{
this.OdataChildren.Add(child.NodeId);
}
this.UpdateChanges();
}