No relational database is going to allow the update of a table record's primary-key. Once the primary-key has been assigned to a database table record, that's it, it is static and unchangeable.
Entity Framework MVVM Update Primary Key
I am using MVVM and Entity Framework to do a CRUD application. I am using INotifyPropertyChanged in a ViewModelBase class.
My data is present in a DataGrid. If I update the fields in the datagrid and use SaveChnages, it works for ALL fields apart from the primary key update.
Is there a way to determine the changes to the primary key field BEFORE and AFTER Update and then I can use a FromSqlRaw to produce and update command if the primary key has changed.
Would this be the correct way to update primary keys?
The table is a reference table with allowed values for other tables which are cascade updated so I cannot delete and insert the reference data values as it would then destroy the data in the other tables.
Sign in to comment
Sort by: Most helpful