Print Page | Close Window

BaseEntity - Auditable Entity and Auditing

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce Classic
Forum Discription: For .NET 2.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=724
Printed Date: 28-Apr-2024 at 5:54am


Topic: BaseEntity - Auditable Entity and Auditing
Posted By: HFloyd
Subject: BaseEntity - Auditable Entity and Auditing
Date Posted: 13-Mar-2008 at 12:56pm
Hi,

I am making slow progress with my first CAB app. I used the Wizard and then used the "IdeaBlade Object Mapper" to attach to my own database (in which I have both my own business tables as well as several of the "application" tables I copied from the IdeaBlade Tutorial DB).

The questions I have relate to the implementation of Auditing... I didn't see any explanation of Auditing in the PDF doc nor on the website/forums.

So, to the questions:

1. What is the difference between "BaseEntity" and "AuditableEntity"? My guess would be that any BOs I want audited should inherit from "AuditableEntity"?

2. Since I deleted the "Employee" class, I get a build error at this point (AuditableEntity):

    /// <summary>Set the global entity "Audit Columns" for this application.</summary>
    /// <remarks>
    /// Modeled on the columns in the Employee entity.
    /// </remarks>
    private static void SetGlobalAuditColumns() {
      AuditColumnManager.SetGlobalAuditColumns(
        Employee.CrtnUsrIdEntityColumn.ColumnName,
        Employee.CrtnTsEntityColumn.ColumnName,
        Employee.ModUsrIdEntityColumn.ColumnName,
        Employee.ModTsEntityColumn.ColumnName
        );
    }

I assume that this has to do with assigning the "who created or modified this record" data to each row...

Since I kept the Users table, I assumed that I could use that to determine the "who" rather than the Employee, so I changed the code to:

private static void SetGlobalAuditColumns() {
      AuditColumnManager.SetGlobalAuditColumns(
        SecurityUser.CreatedByUserIdEntityColumn.ColumnName,
        SecurityUser.CreatedDateEntityColumn.ColumnName,
        SecurityUser.ModifiedByUserIdEntityColumn.ColumnName,
        SecurityUser.ModifiedDateEntityColumn.ColumnName
        );


I was able to build/run the application, but I just want to be sure I am on the right track here...

Thanks!

Heather



Replies:
Posted By: orcities
Date Posted: 21-Mar-2008 at 12:48pm
You are on the right track. Each time you want to be able to audit a table you need to inherit the AuditableEntity. Will also need to add entries into the metaEntityClass and metaEntityProperty tables to coincide with the table.


Posted By: HFloyd
Date Posted: 17-Apr-2008 at 10:05am
Thanks, orcities, for that tip about the metaEntityClass and metaEntityProperty tables - I wouldn't have figured that out.

I had no problem adding all my classes to the metaEntityClass table, but am a bit unsure what I am supposed to put into the metaEntityProperty table.

Am I supposed to put all my class properties into that table? Any tips for doing that in a fast or automated way?

Heather



Posted By: orcities
Date Posted: 17-Apr-2008 at 10:23am
I haven't done it yet, but I intend to build a module that allows me to set/add info to those tables. This will allow a user to update which fields they want to track. For now I did it by hand.
 
You could also just write a query to add all the properties to the table directly in SQL Server Manager. Then just go through and update the ways to track (i.e. edit, add, delete).


Posted By: HFloyd
Date Posted: 17-Apr-2008 at 10:41am
Have a bit of pseudo code for the suggested SQL?

Thanks, Heather


Posted By: orcities
Date Posted: 17-Apr-2008 at 11:00am

you will need to look up cursors/loops for transact sql as well as the built in functions for getting the tables in the database and the properties in the tables

 
foreach table in database
foreach property in table
     add prop to table


Posted By: Bill Jensen
Date Posted: 18-Apr-2008 at 11:55am
I haven't studied the auditing capabilities in detail yet.  You guys probably know more than I do.
 
Ward created the auditing capability in Cabana primarily as a demonstration.  I'm not sure he envisioned it's being used as a base framework for other applications.
 
I agree with Dan that a Cabana module to manage the EntityClass and EntityProperty model objects is in order--a simple SummaryDetail or SearchSummaryDetail page should do the job.  That would get you the ability to manually add, delete and edit the metadata for audited entities (assuming they inherit from AuditableEntity). 
 
I could also imagine a view that displays a grid of all entities that inherit from AuditableEntity with check boxes to automatically populate the EntityClass objects.  A similar mechanism might be used on each EntityClass object to populate its child EntityProperty objects.
 
I think I'd prefer this approach rather than doing it directly using TSQL in the database.
 
Bill J.



Print Page | Close Window