Gianni Rivera
Gianni Rivera

Reputation: 95

Update Id Primary Key field with C#

Hai, like the title.. I just wanna make sure how if I want to update primary key in LINQ? I did google and found that it`s impossible to update Id in Linq. the other way is I delete the old record and insert new but the problem is it will be not effective if the table has a relationship with other table..maybe someone give me a better way to solve it.

Thanks in advance

Upvotes: 0

Views: 511

Answers (1)

nvogel
nvogel

Reputation: 25526

If there are dependent rows in another table then you either need to enable the ON UPDATE CASCADE option on the foreign key constraint(s) OR you need to update TWO rows simultaneously. Otherwise you will get a constraint violation error.

Upvotes: 1

Related Questions