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
causesame savedcause, and, if so, change value of flag in savedcause - insert new
causedbcontext
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
Post a Comment