I am trying to save changes to a record, however I am getting the error
Violation of PRIMARY KEY constraint 'PK_TStoreAssignment'. Cannot insert duplicate key in object 'TAssignment'. The statement has been terminated.
Here is the subsonic query
Dim current = DB.Select().From(TStoreAssignment.Schema) _
.Where("assignmentID").IsEqualTo(selectedRow.AssignmentID) _
.ExecuteSingle(Of TStoreAssignment)()
'Modify the sequence
current.ManualSequence = 999
current.Save()
I see two possibilities for this error:
ManualSequence
is (part of) the primary key ofTStoreAssignment
, and you already have an other entry with 999or (probably) SubSonic thinks
current
is a new object and tries to insert it instead of updating it when you callSave()
. You can debug and check theIsNew
property. If that's the case, you may callMarkOld()
before theSave
method. Or even better, use something like: