I have been trying to do a very simple auditing scenario following Ayende\'s blog which seem to be the resource everyone is refering to when it comes to IPreUpdateEventListe
I ran into this exact issue. This is how I fixed it:
public class MyFlushEntityEventListener : DefaultFlushEntityEventListener
{
protected override void DirtyCheck(FlushEntityEvent e)
{
base.DirtyCheck(e);
if (e.DirtyProperties != null &&
e.DirtyProperties.Any() &&
//ITrackUpdate is my inteface for audited entities
e.Entity is ITrackUpdate)
e.DirtyProperties = e.DirtyProperties
.Concat(GetAdditionalDirtyProperties(e)).ToArray();
}
static IEnumerable<int> GetAdditionalDirtyProperties(FlushEntityEvent @event)
{
yield return Array.IndexOf(@event.EntityEntry.Persister.PropertyNames,
"UpdateTime");
yield return Array.IndexOf(@event.EntityEntry.Persister.PropertyNames,
"UpdateUser");
//You can add any additional properties here.
//Some of my entities do not track the user, for example.
}
}
Then, just replace the event listener in the NH config file:
<listener type="flush-entity"
class="MyFlushEntityEventListener, MyAssembly"/>
I had the same issue, however I found I could work around it by using OnFlushDirty
.
You can find my solution here.