Page 1 of 1

Verifying if an entity object is modified

Posted: Thu 30 Jun 2011 11:57
by dcuser
Hi,

We have entity objects where 2 fields UpdateUserId and UpdateDate needs to be set if an object is modified. When I check the object's EntityState, it shows it as Modified even when it is not. Is there a better way to check if something has changed in the object?

Thanks,

Uday

Posted: Tue 05 Jul 2011 12:47
by AndreyR
First, sorry for the delay.
You can try to find out which properties were modified:

Code: Select all

var changed = context.ObjectStateManager.GetObjectStateEntries(EntityState.Modified);
foreach(var entry in changed) {
  var properties = entry.GetModifiedProperties();
However, an entity should not be marked as Modified if it wasn't modified explicitly.
Please check that your code does not modify the entities.