更新后ObjectStateManager状态未更改

时间:2017-10-25 09:34:48

标签: c# linq entity-framework-6 dbcontext

我想获得更新后已更改的所有属性,实际上我更改了一些属性而不是所有属性,我想知道哪个属性已更新!!我使用ObjectStateManager获取条目的 状态 ,但它始终显示 UNCHANGED !!请任何人帮助我

var db = new DataAccess.ApplicationDbContext();
var employee_db = db.Employees.Find(employee.Id);
employee_db.Tell = employee.Tell;
employee_db.EmailAddress = employee.EmailAddress
db.SaveChanges();

ObjectStateEntry entry = 
 ((IObjectContextAdapter)db).ObjectContext.ObjectStateManager.GetObjectStateEntry(employee_db);


        foreach (string property in entry.GetModifiedProperties())
                {
    ...// just jump out of the loop, means nothing changed
    }

实际上我的更改已正确保存,但状态显示未更改

我还为employee_db使用了refresh方法,但它没有解决问题

EDITED

我希望通过此代码获取所有已更改的属性

       foreach (string property in entry.GetModifiedProperties())
            {

                object oldValue = entry.OriginalValues[property];
                object newValue = entry.CurrentValues[property];
}

0 个答案:

没有答案