c# - The property 'name' is part of the object's key information and cannot be modified. Entity Framework -


i trying update record , error message after context.savechanges();

the property 'name' part of object's key information , cannot modified.

here code update function:

 if (context.eat_sourcenames.any(e => e.name == newsourcename))  {     messagebox.show("name exists in database");  }  else  {     var nametoupdate = context.eat_sourcenames.singleordefault(e => e.name == sourcename.name);     if (nametoupdate != null)     {        nametoupdate.name = newsourcename;        context.savechanges();        refreshdgvs();      }  } 

my sourcenames class looks following:

    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; } 

i searched similar questions, not find working solution.

see answer yildizm85 question: entity framework not working on table without identity column

"entity framework requires primary key generate model database. if there no primary key on table select non-nullable columns concatenated primary key , entity read/only."

looking @ eat_sourcenames object appears there no primary key field entity framework using column 'name' part of composite key means read-only.

the solution add primary key field eat_sourcenames , 'name' field no longer part of primary key.


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

datatable - Matlab struct computations -