Hello,
I'm struggling a bit with ho I could best achieve an "AttachToGraph" functionality.
The purpose is to apply changes from one object graph to another one.
Imagine you have to object graphs of arbitrary depth, one with nodes A-B-C-D-E , and another one with nodes C-D-E-F-G. The nodes C-D-E are logically equal entities, but not the same object instances. (The graphs are the result of deserialized entities)
Now it's quite simple to "flatten" both graphs to a list using the ObjectGraphUtils.ProduceTopologyOrderedList and compute the "Added' and "RemovedEntities"
For instance in our example the "removed entities" will be A & B (present in the first graph, but not in the second) and the "added entities" will be F & G
Now suppose I want to "patch" the original graph so it becomes logically equal to the second graph. For nodes A & B it's easy, I can just "DetachFromGraph". But I cannot easily "AttachToGraph" copies of the nodes F & G.
I am now playing with methods like IEntity2.GetRelations, GetRelatedData, GetDependentRelations, etc .. but i feel like i'm going to complex with this.
Basically the bottomline is : when you have 2 entities (given as IEntity2), that are related by some relation, how can you attach them to eachother ?
Am I correct in thinking that I should investigate the GetRelations, and when I find a proper relation use the method SetRelatedEntity(Property) ? But that gets tricky for "hierarchical" entities, for instance a GroupEntity, that has a "ParentGroup" (meaning it also has "ChildGroups". It has then 2 relationships with GroupEntity...