Home > other >  Attribute "u_m1" is part of the object's key information and cannot be modified.
Attribute "u_m1" is part of the object's key information and cannot be modified.

Time:10-04


Such as topic, try to use entity class to modify database main error when the key field, former title, the primary key is not other table reference, a new one, then change also will go wrong,

The database table structure:

It is not on the field, but is cannot be modified, this is how to return a responsibility?
Entity classes:
Public partial class u_m
{
[Key]
[the Column (" u_m ")]
While [StringLength (16)]
[DisplayName (" code ")]
Public string u_m1 {get; The set; }

While [StringLength (16)]
[DisplayName (" name "))
Public string description {get; The set; }
While [StringLength (64)]
[DisplayName (" note ")]
Public string note {get; The set; }
}

Chen Jinwei

CodePudding user response:

Hi Chen Jinwei,
I made a search on the Internet, it seems that EF doesn't support directly to the primary key changes, perhaps you can try to use stored procedures to implement it,
Here are some links you can consult:
https://stackoverflow.com/questions/1367751/update-primary-key-value-using-entity-framework;
https://stackoverflow.com/questions/29675081/how-to-update-primary-key-from-entity-framework/29675248,
Regards,
Kyle

CodePudding user response:

Oh oh, so that seems to modify the primary key can only be used to delete - "a new way to realize the Chen Jinwei

CodePudding user response:


But I modified and two tables, the primary key table column can be modified, the other one table column can be modified, the other columns cannot be modified, is this why
  • Related