entity framework - EF Update using EntityState.Modified -


usually i'm using code

member member = ctx.members.find(id); member.name = txtname.text; ctx.entry(member).state = entitystate.modified; ctx.savechanges(); 

when want update model using entity framework. found example on so doesn't use entitystate.modified update model. try remove line , it's still working. pros , cons use entitystate.modified , doesn't use entitystate.modified?

notes: i'm using entity framework 6 code first in winforms

the entitystate.modified useless in case because entity updating tracked context retrieve context.

you need in following scenario don't retrieve entity context :

member member = new member({id=1, name="member"}) ; context.entry(member).state = entitystate.modified;  context.savechanges(); 

also, specified in previous answer, context tracks limited "view" of database , therefore need init tracking manually above.

microsoft doc


Comments

Popular posts from this blog

javascript - three.js lot of meshes optimization -

smartface.io - Proper way to change color scheme for whole application -

Email notification in google apps script -