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

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -