Best Practice for Row Level Audit Fields

Posts   
 
    
sqlmatt
User
Posts: 3
Joined: 14-Aug-2007
# Posted on: 24-Aug-2007 17:04:57   

Using: LLBLGen 2.5 & SQL Server 2005

Most of our tables will have information such as create date and last modified date. For the create date, I have seen in the forums the suggestion to have a default value on the table which is inline with what we were planning. The question I have is for the modification date. What do you find as a best practice and convenience for getting the row's last modification date set appropriately?

arschr
User
Posts: 894
Joined: 14-Dec-2003
# Posted on: 24-Aug-2007 18:15:09   

What do you find as a best practice and convenience for getting the row's last modification date set appropriately?

I use Sql Server. With it, I like to use an update trigger.

jmeckley
User
Posts: 403
Joined: 05-Jul-2006
# Posted on: 24-Aug-2007 18:48:21   

if you want this in the business logic you can override the OnBeforeDelete method and check 1. if the entity IsNew 2. if the field exists

something like this

    public partial class DataAccessAdapter
    {
        protected override void OnBeforeEntitySave(IEntity2 entitySaved, bool insertAction)
        {
            if (entitySaved.Fields["UpdatedOn"] != null && !entitySaved.IsNew)
            {
                entitySaved.SetNewFieldValue("UpdatedOn", DateTime.Now);
            }
            base.OnBeforeEntitySave(entitySaved, insertAction);
        }
    }

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 25-Aug-2007 09:14:24   

Or use the new v2.5 AuditorClasses via Dependency Injection, so you can separate the audit logic and generalize it if you need to. For more info read LLBLGenPro(2.5) Help - Using generated code - Setting up and using Auditing

David Elizondo | LLBLGen Support Team
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39910
Joined: 17-Aug-2003
# Posted on: 25-Aug-2007 09:47:46   

Auditing as it is build into v2.5 is designed to be a recorder for actions that were successfully completed.

You could use the set field audit action to log into the entity who changed what. simple_smile

Frans Bouma | Lead developer LLBLGen Pro