Hi Tuna,
Thanks for your response.
Do you mean I should write the row to be deleted to the history table
in the event listener?
If so, this is a solution that would work, however I'd prefer to have
triggers, so that any changes made via raw SQL are also audited...
Does anyone else have any other suggestions? Surely this is quite a
normal thing to want to do these days with SOX compliance etc.?
Mark
On Oct 6, 4:22 pm, "Tuna Toksöz" <[EMAIL PROTECTED]> wrote:
> Why do you use Trigger? Just use event listeners instead of triggers so you
> are done?
>
>
>
> On Mon, Oct 6, 2008 at 3:38 PM, Oz <[EMAIL PROTECTED]> wrote:
>
> > Dear NHUsers,
>
> > I read your Gabriel Schenker's soft deletes article (http://
> >www.nhforge.org/blogs/nhibernate/archive/2008/09/06/soft-deletes.aspx)
> > with great interest and it was very useful! I have a similar but
> > slightly different requirement which I'm having some trouble
> > implementing, and I wonder if you're able to offer some advice?
>
> > I need to actually do a physical delete from a table, but to update
> > the "ModifiedDate" and "ModifiedBy" fields on the object BEFORE
> > deletion. The reason I need to do this is that I have a trigger that
> > will fire on deletions, and copy the row to a history table. I'd like
> > the row in the history table to reference the actual deletion time and
> > have the name of the person who deleted it.
>
> > At the moment, the code I have is as follows, although I have tried
> > various different options.
>
> > protected override void
> > DeleteEntity(NHibernate.Event.IEventSource session, object entity,
> > NHibernate.Engine.EntityEntry entityEntry, bool
> > isCascadeDeleteEnabled,
> > NHibernate.Persister.Entity.IEntityPersister persister,
> > Iesi.Collections.ISet transientEntities)
> > {
> > IAuditable auditable = entity as IAuditable;
>
> > if (auditable != null)
> > {
> > auditable.ModifiedDate = DateTime.Now;
> > auditable.ModifiedBy = "mark";
>
> > CascadeBeforeDelete(session, persister, auditable,
> > entityEntry, transientEntities);
> > base.DeleteEntity(session, auditable, entityEntry,
> > isCascadeDeleteEnabled, persister, transientEntities);
> > CascadeAfterDelete(session, persister, auditable,
> > transientEntities);
> > }
> > else
> > {
> > base.DeleteEntity(session, entity, entityEntry,
> > isCascadeDeleteEnabled, persister, transientEntities);
> > }
> > }
>
> > The code above simply deletes the row, without propagating the update
> > first. I've also tried doing a session.Update(...) before the
> > CascadeBeforeDelete to no avail.
>
> > I wonder if you could offer any suggestions! I'm quite new to
> > NHibernate, but appreciate its power and convenience :-)
>
> > Kindest regards,
>
> > Mark
>
> --
> Tuna Toksöz
>
> Typos included to enhance the readers attention!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"nhusers" group.
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
-~----------~----~----~----~------~----~------~--~---