In my child object I have a DLLine property which is a line number that needs to be unique. In the database there is a UNIQUE index on the parent reference and DLLine.
During editing (including adding new lines, updating existing and deleting lines) and also re-numbering the lines I make sure that the DLLine is unique.
The Update template code includes:
For Each item As EditableChild In Me
If item.IsNew Then
item.Insert(parent)
Else
item.Update(parent)
End If
Next
The problem is that Inserts and Updates are intermixed so that a line can be Inserted with a DLLine number that is currently in the database because that line had not yet been updated to its new DLLine number.
I think the Updates should all be done first, then the Inserts (i.e. 2 seperate loops), so the template code should be:
For Each item As EditableChild In Me
If Not item.IsNew Then
item.Update(parent)
End If
Next
For Each item As EditableChild In Me
If item.IsNew Then
item.Insert(parent)
End If
Next
Bill
I was just worried that there might have been a specific reason for the way the code was, although I couldn't think of one.
Copyright (c) Marimer LLC