开发者

Field change tracking in Entity Framework

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜