Standard Created On / Last Modified On Fields

Posts   
 
    
Kodiak
User
Posts: 92
Joined: 13-Apr-2009
# Posted on: 13-Apr-2009 08:52:14   

Hi,

I'm new to LLBL Gen and wondering how others record the basic Last Modified On, Last Modified By and Created By, Created On information against records.

Each of my database tables has the necessary columns to record the datetimes and user IDs but I'm wondering how to incorporate this into the actual code without going into each entity and adding in the necessary logic.

I've seen the CommonEntityBase class - how would I go about adding this logic here?

Any help would be much appreciated.

Kodiak
User
Posts: 92
Joined: 13-Apr-2009
# Posted on: 13-Apr-2009 09:11:15   

Also as this data is to be displayed in the status bar of most forms which also inherit from a common base, should I created properties which read this data in the CommonEntityBase?

Would this trigger an extra trip to the database each time to retrieve this data in the case of Usernames (which are recorded against the entities as only the IDs)?

The way I can see of doing it now would load a user record by ID to display the Created By and Modified By data.

Just wondering what others think is the cleanest and most efficient way of doing these kind of operations with LLBLGen.

Kodiak
User
Posts: 92
Joined: 13-Apr-2009
# Posted on: 13-Apr-2009 10:08:24   

sorry - forgot to mention I'm using the SelfServicing with TwoClassFiles in VS2008.

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 13-Apr-2009 10:21:40   

You may use our Auditing framework to record..data like CreatedDate, CreatedBy, ModifiedDate, ModifiedBY.....etc. Might also be done in Validation (ValidateEntityBeforeSave)

Some related links: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=13880 http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=9570 http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=8184

Personaly I prefer using a common validator and implement ValidateEntityBeforeSave, to fill these fields so they get saved in the same Save query with the other entity fields.

Kodiak
User
Posts: 92
Joined: 13-Apr-2009
# Posted on: 13-Apr-2009 11:01:49   

In the end I added the following code to the commonentitybase:

        Protected Overrides Sub OnSave()

            If Me.IsNew Then
                If Me.Fields("CreatedBy") IsNot Nothing Then
                    Me.SetNewFieldValue("CreatedBy", CurrentEmployee.ID)
                    Me.SetNewFieldValue("CreatedOn", DateTime.Now)
                End If
            ElseIf Me.IsDirty Then
                Me.SetNewFieldValue("ModifiedBy", CurrentEmployee.ID)
                Me.SetNewFieldValue("ModifiedOn", DateTime.Now)
            End If


            MyBase.OnSave()
        End Sub

And so far appears to be working ok.