c# - EF7 - How to get values from DbSet before change -
i try value of entity stored in dbset before changed code , before saved. however, when try linq single
statement changed value. i'm using ef7.
here's code:
dbset<entity> dbset = context.dbset; entity ent = dbset.single(x => x.id == id); ent.firstname = "new name"; entity entitybeforechange = dbset.single(x => x.id == id); //here want entity old values, if that's important need read without modifying instance context.savechanges();
hope clear enough , can help
you can detach
entity context. keep in mind you'll have pull context before update other, attached entity.
dbset<entity> dbset = context.dbset; entity ent = dbset.single(x => x.id == id); entity entitybeforechange = dbset.single(x => x.id == id); context.entry(entitybeforechange).state = entitystate.detached; // severs connection context ent.firstname = "new name"; context.savechanges();
Comments
Post a Comment