문제

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:

  • Either ManualSequence is (part of) the primary key of TStoreAssignment, and you already have an other entry with 999
  • or (probably) SubSonic thinks current is a new object and tries to insert it instead of updating it when you call Save(). You can debug and check the IsNewproperty. If that's the case, you may call MarkOld() before the Save method. Or even better, use something like:

    DB.Update().From(Of TStoreAssignment)() _
        .Set(TStoreAssignment.ManualSequenceColumn).EqualTo(999) _
        .Where(TStoreAssignment.AssignementIDColumn).IsEqualTo(selectedRow.AssignmentID) _
        .Execute()
    
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top