Build Version: 5.5 (5.5.0) RTM, Build Date: 02-Nov-2018
Project: Adapter project targetting .NET 4.5.2
Database: MS Sql on 2016
We have a Table called CalculatedValue, and a child table called CalculatedValueVariable used to model formulas. The variable table has a nullable FK to Calculated Value. In our application users can modify the formula and individual variables and then click Save. On save, synchronization logic fires that does standard create/update/delete logic. When a variable is removed the following happens:
1) The entity is removed from entity Collection on its parent CalculatedValue record. Each deleted record is placed in an entity collection called deletedVars.
2) Adapter.deleteEntityCollection is called on deletedVars
3) Adapter.Save is called on the parent CalculatedValue record, with refetch and recurse set to true. We're leveraging recurse here to save any new/updated Variable entities.
Looking through other posts, it seems like this error can happen when an update effects zero records in the database. I did a SQL trace and it looks like the following SQL runs when I delete a single variable on an existing CalculatedValue and update the formula string to remove the now-deleted variable.
1) A Delete for the variable we deleted
2) An Update for the CalculatedValue record
3) An update query targeting the deleted variable which attempts to set the FK that points to their parent CalculatedValue record to null
In this case, the second update returns zero results because the variable records were already deleted.
Any tips for getting around this or is there a better way to do what we're doing? I know I could save the parent record recursively first, and then delete the child records after and reload the record, but that seems counterintuitive.