What is the equivalent of ObjectContext.ApplyCurrentValues for DbContext

前端 未结 1 1841
灰色年华
灰色年华 2020-12-25 12:00

What is the equivalent of ObjectContext.ApplyCurrentValues for DbContext?

相关标签:
1条回答
  • 2020-12-25 12:53

    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 .

    0 讨论(0)
提交回复
热议问题