Search This Blog

Thursday, September 7, 2017

How to implement the CreatedBy, CreatedOn and UpdatedBy, UpdatedOn properties in a business class

I would like to promote a KB article, which may be interesting for users who are just getting started with our application framework. This information is actually not new and it was already available in the FAQ and Reference sections of our online documentation as well as the support knowledge base.

I must emphasize that there are actually many ways to implement such auditing properties, and your current code may differ from what we show. For instance, one may declare it as "internal  set {...}" or use the PersistentAlias attribute. Just do not be at all concerned. 

You are welcome to share your own implementations in post comments - maybe we can vote for the most concise and beautiful code, eh?:-P


  1. An observation, it's probably better to use Nameof() in the SetPropertyValue calls.

    Another, if you're using the Persistent/PersistentAlias pattern, you should be aware of calling OnPropertyChanged otherwise you can run into issues when trying to use partial SQL updates, see comments in T513152.

    Yet another observation... adding the audit information is useful, but does come with an unexpected performance penalty. You are adding loads more SQL SELECTs to populate the user classes. If there is fan-out from your user class to other tables, then this is added as well.

    And finally, UpdatedOn is probably a good candidate field for an index if you're performing bulk updates / integrating with other systems.

    Someone has also mentioned NonCloneable attribute in the topic.

    Something else with considering is whether you should explicitly store dates as UTC and make use of [ValueConverter(typeof(UtcDateTimeConverter))] decoration.

    1. We'll mention some of these optional additions in the source article. Thanks for sharing, Chris.