I have a grid with the datasource set to an EntitySpaces collection, with a checkbox column. When the checkbox is checked, I want to create a record and when it is cleared I want to delete the same record.
To avoid the obvious PK violation save if a user repeatedly checks and unchecks an item, I am trying to retrieve the previously deleted entities and mark them as not deleted. However, when I use CombineDeletedEntities
and SeparateDeletedEntities
on the collection it creates duplicate entries in the collection.
roleFunctions.CombineDeletedEntities();
// On third cycle through, this is the error line
RoleFunction foundItem = roleFunctions.FindByPrimaryKey(roleName, functionName);
if (foundItem != null)
{
foundItem.RowState = esDataRowState.Unchanged;
// Extraneous logic...
}
else
{
// Create new item...
}
roleFunctions.SeparateDeletedEntities();
So basically when I do FindByPrimaryKey
the third time, EntitySpaces has created an extra item somehow which causes an InvalidOperationException
with a message of Sequence contains more than one matching element
.
Has anyone hit this with EntitySpaces before and how did you end up nicely handling a user creating and deleting the same entity multiple times in a single session?