c# - DbUpdateConcurrencyException for tables with foreign keys -


update: ahh! dumb error: had 2 instances of repository available, and, our implemntation requires provide connection string each repo, 2 repos pointing different databases, , adding entity 1 db another, , id not found in updated db.


i'm running .net mvc 4.0, ef 5. implement repository pattern. in following delete method of webapi controller have following code:

int userid = userhelper.getcurrentuserid(); datetime = datetime.utcnow;  exhibitlinkrepository el = new exhibitlinkrepository(); el.setcase = caseid;  exhibitlink link = el.all.singleordefault(l => l.id == id);  //mark link deleted link.usermodified_id = userid; link.datetimemodified = now; link.deleted_flag = true;  exhibitlinkrepository.insertorupdate(link); exhibitlinkrepository.savechanges(); 

where exhibitlinkrepository.insertorupdate:

public void insertorupdate(exhibitlink exhibitlink)     {     if (exhibitlink.id == default(int))     {         // new entity         context.exhibitlinks.add(exhibitlink);     }     else     {         // existing entity         context.entry(exhibitlink).state = entitystate.modified;      } } 

when invoke context.savechanges() dreaded:

store update, insert, or delete statement affected unexpected number of rows (0). entities may have been modified or deleted since entities loaded. refresh objectstatemanager entries.

now, exhibitlink table has foreign key constraints follows: enter image description here

there happen triggers on underlying db of these related tables, disabling them did not change outcome.

i don't it. ideas?


Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -