EF Update using EntityState.Modified

entity-framework

Accepted Answer

Since the entity you are modifying is already being tracked by the context when you retrieve it from the context, the EntityState.Modified property is useless in your situation.

In the event that you fail to extract your entity from the context, you will require it:

Member member = new Member({Id=1, Name="member"}) ;
context.Entry(member).State = EntityState.Modified; 
context.SaveChanges();

Additionally, as mentioned in the previous response, your context occasionally only tracks a constrained "view" of the database, necessitating the manual start of the tracking described above.

Windows doc

16
5/15/2015 5:47:11 AM

Popular Answer

ZZZ_tmp


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow