Look into the IInterceptor on NHibernate, you then register that in the
configuration, and you gain access to the CUD events that NHibernate fires
on the entity side.

On Mon, Sep 14, 2009 at 10:37 PM, Anthony Gatlin <gatl...@gmail.com> wrote:

>
>
> Here are a few Newbie questions. I am sure these are no-brainers for
> those that have worked with FNH or NH for a while, but for me, being a
> Newbie, the answers are elusive. Any suggestions would be appreciated.
>
> In my database, I have approximate 150 tables. Previously, each of
> these tables had 4 pretty standard columns I used for audit purposes.
> These were:
>
> - CreatedOn
> - CreatedBy
> - UpdatedOn
> - Updated By
>
> In my opinion, a better design was to move these into a history (aka
> audit) table. I did. The history table tracks all audit related events
> which occur in the application. This includes both database and other
> application related events. Within the application, every record
> creation or modification triggers a new record in the history table.
> Records in the history table are never modified.The history table now
> contains the following columns
>
> - Id
> - UserId
> - ObjectType <- A textual reference to the name of the table from
> which the history record is associated. A discriminator I think. May
> be null if the event was not related to the Database.
> - ObjectId <- The Foreign Key of the table where the event occurred--
> if any. May be null.
> - EventType <- Tracks the type of action (e.g. Insert, Update, Delete,
> Read, Error)
> - EventMarkup <- XML that actually describes the event detail.
> - CreatedOn
>
> Here are my questions.
>
> 1. For use with NHibernate and Fluent NHibernate, is this the best way
> to model the data, or is there some other model that works better?
>
> 2. If this model is appropriate, how do I effectively map this data in
> FNH so that:
> a) a record can easily be created in the history table when a change
> is made to any of the other database tables. (If we can map this, is
> it possible to make it auto-populate the discriminator?)
> b) it is possible to query the history table for a list of records
> that relate to a given object.
> c) records can be included for application events which do not refer
> to a data model event. (In other words, how can set up the map to
> allow ObjectType and ObjectID to be occasionally blank--or is this
> even possible?)
>
> (Note: I still do retain a CreatedOn column in each table. Since I use
> Guids for primary keys, I use the CreatedOn column for my clustered
> index. As I don't yet know how to change the clustered index through
> FNH or NH, I am just updating it through SQL scripts. I know! I know!
> I am violating the fundamental rule of NH which is to let it handle
> all of the underlying DB access.)
>
> Thanks in advance!
>
> >
>


-- 
- Hudson
http://www.bestguesstheory.com
http://twitter.com/HudsonAkridge

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Fluent NHibernate" group.
To post to this group, send email to fluent-nhibernate@googlegroups.com
To unsubscribe from this group, send email to 
fluent-nhibernate+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/fluent-nhibernate?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to