Postgres database contains product table with natural primary key:
create table product ( productcode char(10) primary key, price numeric(12,2), ... lot of other columns );
and other similar tables with natural primary keys.
ASP.NET 5 MVC application is used to update it using EF Core with
Npgsql data provider.
If product code is also changed, EF Core throws error
The property 'Product.Productcode' is part of a key and so cannot be
modified or marked as modified. To change the principal of an existing
entity with an identifying foreign key, first delete the dependent and
invoke 'SaveChanges', and then associate the dependent with the new
Product code is used as foreign key in other tables (with ON UPDATE CASCADE clause) so it cannot deleted.
Database structure change is not an option.
How to allow update primary key field also ?
Block this check in EF Core, e.q setting old value to same as new value forcibly before update.
Set primary key to some other value before saving changes.
Force EF Core to create update statement and execute it manally
Use some EF Core extension or other framework.
Change Npgsql EF core provider to allow this.
Which is best way to implement this without changing database structure?