Select to view content in your preferred language

Delete Associations fails in a EditOperation

153
1
Jump to solution
12-01-2024 09:57 PM
rohanrajan_hms
Regular Contributor

I am trying to programmatically delete features in ArcGIS Pro SDK. And if they have associations, I am trying to delete the Associations and then delete the feature using the  CreateChainedOperation method. But I get this error. What am I doing wrong?

Even the Delete Associations did not work when tried separately even without chaining

Any advice on this will be much appreciated. 

Thank You

rohanrajan_hms_0-1733118803496.png

 

EditOperation deleteAssociationOperation = new();
deleteAssociationOperation.Callback(context => {

foreach (var assoc in assocs)
{

LogMessage($"Deleting Association: {assoc.Type}");
context.Invalidate(row);
AssociationDescription associationToDelete = new(assoc.Type, new RowHandle(assoc.FromElement, UN), new RowHandle(assoc.ToElement, UN));
deleteAssociationOperation.Delete(associationToDelete);
context.Invalidate(row);
}

}, enterpriseTable);
bool resultdelAssoc = await deleteAssociationOperation.ExecuteAsync();
if (!resultdelAssoc)
{
//MessageBox.Show(String.Format($"Could not delete features {row.GetGlobalID()}: {deleteRecordOperation.ErrorMessage}"));
LogMessage($"Could not delete Association {row.GetGlobalID()}: {deleteAssociationOperation.ErrorMessage}");
}
//deleteAssociationOperation.Execute();

else if (resultdelAssoc)
{
LogMessage("Deleting Associations Complete, Deleting Feature");
var chaineddeleteRecordOperation = deleteAssociationOperation.CreateChainedOperation();
// In order to update the Map and/or the attribute table. Has to be called before the delete.
chaineddeleteRecordOperation.Callback(context => {
context.Invalidate(row);
chaineddeleteRecordOperation.Delete(row);
context.Invalidate(row);
}, enterpriseTable);

bool resultDel = await chaineddeleteRecordOperation.ExecuteAsync();
if (!resultDel)
{
//MessageBox.Show(String.Format($"Could not delete features {row.GetGlobalID()}: {deleteRecordOperation.ErrorMessage}"));
LogMessage($"Could not delete features {row.GetGlobalID()}: {chaineddeleteRecordOperation.ErrorMessage}");
}
else if (resultDel)
{
LogMessage("Delete with Association Done");
}
}

0 Kudos
1 Solution

Accepted Solutions
GKmieliauskas
Esri Regular Contributor

Hi, 

As written in ArcGIS Pro ProConcepts Editingyou cannot use edit operation methods within the context of your call back routine or lambda. You use Delete method of EditOperation.

View solution in original post

0 Kudos
1 Reply
GKmieliauskas
Esri Regular Contributor

Hi, 

As written in ArcGIS Pro ProConcepts Editingyou cannot use edit operation methods within the context of your call back routine or lambda. You use Delete method of EditOperation.

0 Kudos