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