Entity.OnSave - Add additional "Logging" records

Posts   
 
    
mshe
User
Posts: 167
Joined: 02-Feb-2006
# Posted on: 12-Jul-2007 22:33:03   

Hello,

I guess this is similar to the LLBLGen 2.5's auditing framework, but is there a way to do something simple in 2.0 (self-servicing)?

For one particular entity, whenever save is called I like to log a couple additional records.

I have currently put the code into the the OnSave function.

However, is there a way to submit the commands as part of a transaction so that they will go through ONLY if the entity was successfully comitted to the database?

This is what I have so far.


 Protected Overrides Sub OnSave()
        If Me.IsNew Then
            Me.EntryDate = Now
        End If

        'Automatically set the update time
        MyBase.UpdateTime = Now

        'If the status field has been changed, we should also log a event model status record
        If Me.Fields(EventModelFieldIndex.Status).IsChanged Then
            Dim _EventModelStatus As New EventModelStatusEntity

            With _EventModelStatus
                .EventModelId = Me.EventModelId
                .Status = Me.Status
                .StatusTime = Now
            End With

            _EventModelStatus.Save()
        End If

        MyBase.OnSave()
    End Sub

I just like to know what the best way is to do this - while maintain some sort of transactional integrity.

Thanks!

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 13-Jul-2007 10:38:55   

Check the following post: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=8417&StartAtMessage=0&#46567

For a Good discussion about auditing, check the following 2 pages long thread: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=3612

I just like to know what the best way is to do this

v.2.5 Auditing Framework wink

mshe
User
Posts: 167
Joined: 02-Feb-2006
# Posted on: 13-Jul-2007 15:22:51   

Walaa wrote:

Check the following post: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=8417&StartAtMessage=0&#46567

For a Good discussion about auditing, check the following 2 pages long thread: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=3612

I just like to know what the best way is to do this

v.2.5 Auditing Framework wink

Wonderful, I think Frans answer in the first message solves the q for me!