c# - Updating using code first in Entity Framework 5 with detached entities -


i developing n-tier application detached entities (visual studio 2010). have not included class definitions seem irrelevant logic.

the following code snippet works correctly , embedded in using dbcontext.

dbcontext.entry(case).state = case.caseid == 0 ? entitystate.added : entitystate.modified; dbcontext.entry(case.woman).state = case.woman.caseid == 0 ? entitystate.added : entitystate.modified; dbcontext.entry(case.summary).state = case.summary.caseid == 0 ? entitystate.added : entitystate.modified;  dbcontext.savechanges(); 

i have added collection icollection<cause> causes summary class.

what want is:

  • check see if new cause same saved cause, and, if so, change value of flag in saved cause
  • insert new cause dbcontext

there flag iscurrent in cause class; there 1 record set true; needs set false if new cause different one.

i welcome code-first based way of doing this.

something should work:

using (...) {     cause c = db.causes.firstordefault(ce => ce.iscurrent == true);     if (cause.title != c.title)     {         c.iscurrent = false;         cause.iscurrent = true;             }      //     // other codes ...     // } 

Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -