Convert your DbContext
to ObjectContext
and try following implementation of IsModified
:
var context = new YourDbContext();
var adapter = (IObjectContextAdapter)context;
var objectContext = adapter.ObjectContext;
...
public bool IsModified()
{
bool modified =
context.ObjectStateManager.GetObjectStateEntries(~EntityState.Unchanged);
.Any();
return modified;
}
you can also try to handle context.ObjectStateManager.ObjectStateManagerChanged
event and update your property in this event. Should be more elegant.