Referring - How to get original values of an entity in Entity Framework? - I tried to extract the original value(s) of an entity in EF. But the ObjectStateManager.GetOBjectStateEntry giving the modified value of the entity. What am I missing?
I am using EF 4.0 (POCO Entities) in a multi-layered environment.
public bool Update(IMessage objMessage)
{
object ob = objMessage.GetMaster();
appSancAdvice _entity = ob as appSancAdvice;
using (var context = new BISEntities())
{
context.appSancAdvices.Attach(_entity);
ObjectStateEntry objectState = context.ObjectStateManager.GetObjectStateEntry(_entity);
objectState.ChangeState(System.Data.EntityState.Modified);
// this is giving the modified value of _entity
var originalValues = context.ObjectStateManager.GetObjectStateEntry(_entity).OriginalValues["sancstatus_id"];
int _i = context.SaveChanges();
return (_i > 0) ? true : false;
}
}