Skip to content Skip to sidebar Skip to footer

How To Update Primary Key From Entity Framework?

I have Table eventid int -- not PK key but with autoincrement jobid -- PK autoincrement disabled userid int -- PK autoincrement disabled To update jobID I do following: var ite

Solution 1:

Updating primary key columns is not a good practice with EntityFramework. It confuses EF because it changes the identity of the object, and makes keeping the in-memory copy and the in-database copy of the data in sync very problematic. So it's not allowed.

Just don't update primary keys. Instead delete one row and insert a new one.

Alternatively you can update the primary key directly with a stored procedure or other query.

Post a Comment for "How To Update Primary Key From Entity Framework?"