我正在尝试更新一个记录,并在context.SaveChanges();之后得到这个错误信息.
The property ‘name’ is part of the object’s key information and cannot be modified.
if (context.EAT_SourceNames.Any(e => e.name == newSourceName)) { MessageBox.Show("Name already exists in the Database"); } else { var nameToUpdate = context.EAT_SourceNames.SingleOrDefault(e => e.name == sourceName.name); if (nameToUpdate != null) { nameToUpdate.name = newSourceName; context.SaveChanges(); RefreshDGVs(); } }
我的SourceNames类看起来像下面这样:
public EAT_SourceNames() { this.EAT_Sources = new ObservableListSource<EAT_Sources>(); } public string name { get; set; } public string version_id { get; set; } public string allocation_name { get; set; }