Revisited: Best practice for "update by" columns

Posts   
 
    
gabrielk avatar
gabrielk
User
Posts: 231
Joined: 01-Feb-2005
# Posted on: 15-Jun-2007 09:38:42   

Hi All,

I've been wondering how to do something like mentioned in 2004:

http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=568&HighLight=1

I would like every entity which as a CreatedBy or UpdatedBy field to have these fields automaticly populated by the current userid. I have a static class which reads this value from the session (webapplication), but I need to have 1 place where I could add this functionality. Since the BaseEntity is in the DLL I was wondering if there's a location in the generated code where all entities pass by when they save...

Suggestions and pointers would be very nice!

Thanks, Gab

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 15-Jun-2007 10:12:02   

The source code of the runtime libraries are available to you, so you can easily modify it and re-build them.

Also please check the Auditing support built into version 2.5: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=9537 You might need it in future designs.

gabrielk avatar
gabrielk
User
Posts: 231
Joined: 01-Feb-2005
# Posted on: 15-Jun-2007 10:16:19   

Hi,

Thanks for the tip... I am always a bit scared of changing those files since I have to redo the changes each time a new version of the runtime dlls comes out, right?

I am seriously considering implementing 2.5 beta already since we're at the still starting phase of a new webframework/application and have a need for the new authorization and auditing functionality.

Auditing could be used for my CreatedBy requirement.

Just a little question:

What happens if you assign a value to the field which is the same as the value it already had? Will it be dirty of does it check on assiging a property if it's a different value or the same.

Cheers, Gab

fpw2377
User
Posts: 35
Joined: 23-Feb-2007
# Posted on: 15-Jun-2007 15:33:21   

Hi Gab,

Well if you are using the Adapter model you can create your own DataAccessAdapter class that inheirets from DataAccessAdapter class and override the OnBeforeEntitySave method to check for those fields and fill them. Do all your fetches and saves using this class instead of the base one. We do this for auditing where I work. Works well.

Frank

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 15-Jun-2007 15:37:48   

What happens if you assign a value to the field which is the same as the value it already had? Will it be dirty of does it check on assiging a property if it's a different value or the same

I think this is always treated as not changed, unless you want the opposite, then again you have to make changes in the runtime libraries. Whether directly or indirectly by inheriting and overriding methods.