c# - Entity Framework: attached objects with children -
c# - Entity Framework: attached objects with children -
as explained in topic if insert or update entity can utilize next approach:
if (myentity.id != 0) {     context.myentities.attach(myentity);     context.objectstatemanager.changeobjectstate(myentity, entitystate.modified); } else {     context.myentities.addobject(myentity); }  context.savechanges();    the problem in case myentity has kid related objects , hence when seek update (myentity.id != 0) receive next exception:
system.invalidoperationexception unhandled message=an object temporary entitykey value cannot attached object context.    if remove kid objects (comment out) myentity works..
does know how solve problem? how can update myentity , save kid objects? thanks!
edit:here solution problem: stackoverflow.com/a/7969372/282649
 c# entity-framework 
 
Comments
Post a Comment