I have created a new enterprise geodatabase on SQL server instance and placed one non-versioned table called in_PubRC_Lines in the geodatabase. When I try run my sample code attached below – a simple demo example that uses the callback function to delete a row – I get the following error: “This edit failed because a short edit operation cannot be performed on versioned data.”
A key point in the code is I set the EditOperationType = EditOperationType.Short. This should the correct operation type for non-versionen enterprise geodatabases.
If I replace the EditOperation.Callback() with a EditOperation.Delete() the code seems to be running fine.
So, this makes me assume that EditOperation.Callback() is only supported for EditOperationType.Long (and for enterprise geodatabase that means versioned data). Unfortunately, the documentation does not clarify this.
internal class Button1 : Button
{
protected override async void OnClick()
{
string tableName = "in_PubRC_Lines";
var map = MapView.Active?.Map;
if (map == null) return;
var searchThisTable = map.GetStandaloneTablesAsFlattenedList().Where(l => l.Name.Equals(tableName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
if (searchThisTable == null)
{
MessageBox.Show($@"Cannot find this table: {tableName}");
return;
}
var table = await QueuedTask.Run(() => { return searchThisTable.GetTable(); });
var deleteOperation = new EditOperation()
{
SelectNewFeatures = false,
EditOperationType = EditOperationType.Short,
Name = $"Delete test"
};
await DeleteDataAsync(table, "ID IN (1)", deleteOperation);
//await QueuedTask.Run(() => { deleteOperation.Delete(table, 1); });
if (!deleteOperation.IsEmpty)
{
var res = await deleteOperation.ExecuteAsync();
if (!res)
{
MessageBox.Show(deleteOperation.ErrorMessage);
}
}
}
private async Task DeleteDataAsync(Table table, string whereClause, EditOperation editOperation)
{
await QueuedTask.Run(() =>
{
editOperation.Callback(context =>
{
QueryFilter qf = new QueryFilter();
qf.WhereClause = whereClause;
using (var cursor = table.Search(qf, false))
{
while (cursor.MoveNext())
{
using (var row = cursor.Current)
{
context.Invalidate(row);
row.Delete();
}
}
}
}, table);
});
}
}