await QueuedTask.Run(() =>
{
var edit_op = new EditOperation()
{
Name = "Delete a Relationship record"
};
//We are going to use mapmembers in this example
//we could equally use feature classes/tables
var kg_layer = mv.Map.GetLayersAsFlattenedList()?
.OfType<ArcGIS.Desktop.Mapping.KnowledgeGraphLayer>().First();
//entities
var entityOrg = kg_layer.GetStandaloneTablesAsFlattenedList()
.First(child_layer => child_layer.Name == "Organization");
var entityPerson = kg_layer.GetStandaloneTablesAsFlattenedList()
.First(child_layer => child_layer.Name == "Person");
//Relationship
var rel_stbl = kg_layer.GetStandaloneTablesAsFlattenedList()
.First(child_layer => child_layer.Name == "HasEmployee");
// get the origin, destination records
Guid guidOrigin = Guid.Empty;
Guid guidDestination = Guid.Empty;
using (var rc = entityOrg.Search())
{
if (rc.MoveNext())
//Use the KnowledgeGraphPropertyInfo to avoid hardcoding...
guidOrigin = rc.Current.GetGlobalID();
}
using (var rc = entityPerson.Search())
{
if (rc.MoveNext())
//Use the KnowledgeGraphPropertyInfo to avoid hardcoding...
guidDestination = rc.Current.GetGlobalID();
}
var rd = new KnowledgeGraphRelationshipDescription(guidOrigin, guidDestination);
edit_op.Delete(rel_stbl, rd);
edit_op.Execute();//Do the delete
});