What is the ObjectContext equivalent? DbContext ApplyCurrentValues

c# entity-framework

Question

What is the equivalent of ObjectContext.ApplyCurrentValues for DbContext?

1
34
4/27/2011 4:46:32 PM

Accepted Answer

There is no equivalent. You can either get the ObjectContext with...

((IObjectContextAdapter)myDbContext).ObjectContext.ApplyCurrentValues(...)

...or use a similar method of DbEntityEntry:

 myDbContext.Entry(originalEntity).CurrentValues.SetValues(changedEntity);

originalEntity represents the object before the change (usually fetched from database before you update). It must be attached to the context. changedEntity represents the entity with the same key which has been changed.

This second approach is probably closely related to the ObjectStateEntry.ApplyCurrentValues method of EF 4.0 .

48
4/27/2011 5:24:56 PM


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