KnowledgeGraphRelationshipDescription Class
Represents a relationship between two entities in a knowledge graph.

Create a new Relationship from Existing Entities 2
var create_rel2 = await QueuedTask.Run(() =>
{
//Instantiate an operation for the Create
var edit_op = new EditOperation()
{
Name = "Create a new relationship record",
SelectNewFeatures = true
};
//Use datasets or feature layer(s) or standalone table(s)
//Get a reference to the KnowledgeGraph
//var kg = ... ;
//We will use a relate called 'HasEmployee' to relate an Organization w/ a Person
//Use either tables or map members to get the rows to be related...
var org_fc = kg.OpenDataset<FeatureClass>("Organization");
var person_tbl = kg.OpenDataset<Table>("Person");
//Get the relationship dataset
//We can use either a table or standalone table
var emp_tbl = kg.OpenDataset<Table>("HasEmployee");
// get the origin, destination records
Guid guidOrigin = Guid.Empty;
Guid guidDestination = Guid.Empty;
using (var rc = org_fc.Search())
{
if (rc.MoveNext())
//Use the KnowledgeGraphPropertyInfo to avoid hardcoding...
guidOrigin = rc.Current.GetGlobalID();
}
using (var rc = person_tbl.Search())
{
if (rc.MoveNext())
//Use the KnowledgeGraphPropertyInfo to avoid hardcoding...
guidDestination = rc.Current.GetGlobalID();
}
//Add any extra attribute information for the relation as needed
var attribs = new Dictionary<string, object>();
attribs["StartDate"] = new DateTimeOffset(DateTime.Now);
var rd = new KnowledgeGraphRelationshipDescription(guidOrigin, guidDestination, attribs);
//Add a create for the relationship to the operation
edit_op.Create(emp_tbl, rd);
//Do the create
return edit_op.Execute();
});
Create a new Relationship and New Entities 2
var createRel = await QueuedTask.Run(() =>
{
//This example uses a KnowledgeGraphRelationshipDescription
var edit_op = new EditOperation()
{
Name = "Create entities and a relationship using a KG relate desc",
SelectNewFeatures = true
};
//We are just 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();
//From the KG Layer get the relevant child feature layer(s) and/or standalone
//table(s)
var org_fl = kg_layer.GetLayersAsFlattenedList().OfType<FeatureLayer>()
.First(child_layer => child_layer.Name == "Organization");
var person_stbl = kg_layer.GetStandaloneTablesAsFlattenedList()
.First(child_layer => child_layer.Name == "Person");
var rel_stbl = kg_layer.GetStandaloneTablesAsFlattenedList()
.First(child_layer => child_layer.Name == "HasEmployee");
var attribs = new Dictionary<string, object>();
//New Organization
attribs["Name"] = "Acme Ltd.";
attribs["Description"] = "Specializes in household items";
attribs["SHAPE"] = org_location;
//Add it to the operation - we need the rowtoken
var rowtoken_org = edit_op.Create(org_fl, attribs);
attribs.Clear();//we are going to re-use the dictionary
//New Person
attribs["Name"] = "Bob";
attribs["Age"] = "41";
attribs["Skills"] = "Plumbing, Framing, Flooring";
//Add it to the operation
var rowtoken_person = edit_op.Create(person_stbl, attribs);
attribs.Clear();
//Create the new relationship using a KnowledgeGraphRelationshipDescription
//Row handles act as the placeholders for the TO BE created new entities that will
//be related
var src_row_handle = new RowHandle(rowtoken_org);
var dest_row_handle = new RowHandle(rowtoken_person);
//Add any extra attribute information for the relation as needed
attribs["StartDate"] = new DateTimeOffset(DateTime.Now);
var rel_desc = new KnowledgeGraphRelationshipDescription(
src_row_handle, dest_row_handle, attribs);
//Add the relate description to the edit operation
edit_op.Create(rel_stbl, rel_desc);
//Execute the create of the entities and relationship
return edit_op.Execute();
});
Delete a Relationship record 2
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
});
Target Platforms: Windows 11, Windows 10
ArcGIS Pro version: 3.4 or higher.