I use the EditOperation class to do some edits, and also RelationshipClass.DeleteRelationship to delete a features's relationship to another table.
When I undo the edits using the standard Undo tool, edits are reverted properly, but relationships are not restored. This makes sense, because the relationshipclass has no knowledge of the EditOperation.
Is there a way to make this work?
This should work if you delete the relationships with a callback within the same edit operation.
In this example I'm modifying a selected parcel with an inspector and deleting the relationships with a callback. Note, this is quick and dirty code:
QueuedTask.Run(() =>
{
//get selected parcel
var selfeature = MapView.Active.Map.GetSelection();
//create the editop and modify
var op = new EditOperation();
op.Name = "Update and delete relationship";
var insp = new Inspector();
insp.Load(selfeature.Keys.First(), selfeature.Values.First());
insp["ZONING"] = 42;
op.Modify(insp);
//delete the relationship through callback
var geodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(@"d:\temp\prorel\test.gdb")));
var relationshipClass = geodatabase.OpenDataset<RelationshipClass>("parcels_owners");
//get the selected parcel as a row
var parcelFeatureClass = geodatabase.OpenDataset<FeatureClass>("parcels");
var queryFilter = new QueryFilter { WhereClause = "OBJECTID = " + selfeature.Values.First().First().ToString() };
var rowCursor = parcelFeatureClass.Search(queryFilter, false);
rowCursor.MoveNext();
var selectedrow = rowCursor.Current;
//get the related owner rows
var relatedDestinationRows = relationshipClass.GetRowsRelatedToOriginRows(selfeature.Values.First());
op.Callback(context =>
{
foreach (Row relatedDestinationRow in relatedDestinationRows)
{
relationshipClass.DeleteRelationship(selectedrow, relatedDestinationRow);
}
}, relationshipClass);
op.Execute();
});