Is there a way to find out what field has been changed on my object.
Sample problem : when some开发者_如何学C date field is changed and the changes are being saved custom some custom logic should be applied to related objects.
I am trying to do it before context.SaveChanges();
but ObjectStateManager
doesn't give me all the information I need.
Why to use ObjectStateManager
for that? You have entities which have getter and setter so simply put that logic trigger in setter. You can also implement INotifyPropertyChanged
on your entity and handle event when your required property changes outside of the entity.
Otherwise you must use ObjectStateManager
get ObjectStateEntry
for the entity and compare its CurrentValues
and OriginalValues
. But this is mostly wrong approach. Logic should be triggered by code in the entity.
精彩评论