Ormlite and audit / history

I’m using Ormlite with mysql and I would like to implement an audit/history table for some tables. These tables don’t change frequently.

I saw that ServiceStack supports Audit and and also History for services but for now this db is not behind a Servicestack service and is populated from a legacy system which we will deprecate at some point.

Is there a way to reproduce the Audit/history ServiceStack feature with Ormlite only? It would be nice if it’s possible and would be comptabile with ServiceStack service behaviour once the db is behind a service.

I saw another thread asking this but it’s from 2018 (it didn’t seem possible at that time) and new features related to this have been released since I think.

Thanks.

AuditHistory isn’t an OrmLite feature, it’s an AutoQuery CRUD feature. The docs explain how it uses [AutoPopulate] to populate the request with audit information:

https://docs.servicestack.net/autoquery-crud#advanced-crud-example

So it’s not a magical feature that can be turned on for any table. If I wanted to add Audit Info to random tables I’d have them inherit a base class with info you want populated (e.g. like AuditBase) then create an extension method that I could use to populate its properties when Auto Mapping from a Request DTO to your OrmLite data model, e.g:

Db.Insert(request.ConvertTo<Table>().WithAuditInfo(Request));
1 Like