How to determine if an NHibernate entity was updated
I have an application that mass-updated a load of entities based on external data. Some of them will have not changed. NHibernate is clever enough to know wh开发者_如何学Pythonether the entity has changed and whether or not to send an update when I call DbContext.CommitChanges()
.
But I want to be able to output to screen/log when an entity has been updated.
How do I find out if an update has been executed? How do I hook into Nhibernate change tracking?
NHibernate has an event system you can hook up to. Here is a blog post that explains what you want to do:
NHibernate 2.0 Events and Listeners
Here is the part of the NHibernate tutorial that explains the event system:
Chapter 11. Interceptors and events
And another one:
Creating an Audit Log using NHibernate Events
精彩评论