Re: OnPostDelete event flush problem when I enumerate the DeleteState

38 views
Skip to first unread message

Ricardo Peres

unread,
Jun 22, 2012, 7:21:40 AM6/22/12
to nhu...@googlegroups.com
http://fabiomaulo.blogspot.pt/2011/05/nhibernate-bizarre-audit.html 

On Thursday, June 21, 2012 11:10:52 PM UTC+1, bartp wrote:

The reference properties causes the problem. I skip them now. Someone a clue how to audit them?

On Thursday, June 21, 2012 4:25:36 PM UTC+2, bartp wrote:

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();
        }
Reply all
Reply to author
Forward
0 new messages