LinqToSQL: Not possible to update PrimaryKey?
Posted
by Zuhaib
on Stack Overflow
See other posts from Stack Overflow
or by Zuhaib
Published on 2010-03-24T14:10:16Z
Indexed on
2010/03/24
14:13 UTC
Read the original article
Hit count: 274
I have a simple table (lets call it Table1) that has a NVARCHAR field as the PK. Table1 has no association with any other tables.
When I update Table1's PK column using LinqToSQL it fails. If I update other column it succeeds.
I could delete this row and insert new one in Table1, but I don't want to. There is a transaction table which has Table1's PK column as a column.
When the PK of Table1 is changed I want no effect in the transaction table. But when the row from Table1 is deleted, I want the transaction rows to be deleted. The cascading is done via Trigger.
As there is not association between these two tables, if I update the PK column of Table1 using normal SQL, it works and there is no effect on the transaction table as expected. When I delete the row the trigger deletes the rows from transaction table.
For this reason I can't delete and then add new row in Table1. So what can be done to successfully update the PrimaryKey of the Table1?
© Stack Overflow or respective owner