I'm trying todo audit on my entities. The audit is working for 
OnPostUpdate/OnPostInsert but not for OnPostDelete.

Does anyone have a clue for me?

       public void OnPostDelete(PostDeleteEvent @event)
        {
            if (@event.Entity is AuditLogEntry)
            {
                return;
            }

            var entityFullName = @event.Entity.GetType().FullName;
            var session = @event.Session.GetSession(EntityMode.Poco);

            // cannot use this code, {"collection 
[namesspace.Entities.B.Ds] was not processed by flush()"}
            //var sb = new StringBuilder();
            //for (int i = 0; i <= @event.DeletedState.Length - 1; i++)
            //{
            //    if (@event.DeletedState[i] != null)
            //    {
            //        sb.Append(@event.Persister.PropertyNames[i] + ": ");
            //        sb.AppendLine(@event.DeletedState[i].ToString());
            //    }
            //}  

            session.Save(new AuditLogEntry
            {
                EntityShortName = @event.Entity.GetType().Name,
                EntityFullName = entityFullName,
                //OldValue = sb.ToString(),
                Username = Environment.UserName,
                EntityId = (long)@event.Id,
                AuditEntryType = "Delete",
                Timestamp = DateTime.Now
            });

            session.Flush();
        }

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/nhusers/-/5OG4Qu1fjWsJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to