This question is locked. New answers and comments are not allowed.
Hello,
one of the requirements for a project we are currently developing is to audit changes of persistened objects. There are several different approaches to achieve this and writing database triggers is my final resolve if some sort of relatively simple automatic audit mechanism in OpenAccess cannot be implemented.
The most simple approach would be to either add custom audit logic to the DBContext.SaveChanges() or to catch modification events (Adding/Added etc.) and then audit changes there. The biggest problem is probably getting the old and the new values of the object and the entity type.
Basically the idea is to have all the audit logic in one place and when the object changes all the neccessary information about entity type and old object data are also available and used for writing an audit trail into database table.
Audit table currently looks like this:
AuditLogID
UserID
ObjectID
AuditTypeID
ObjectEntityName
OldData (XML)
NewData (XML)
AuditDate
The point is to save inserted/updated/deleted object into OldData and NewData columns which are XML. UserID is the ID of current user who is making the changes to the object(s). ObjectEntityName holds the name of the entity (basically table name). AuditTypeID is used for identifying the type of change ie. select/insert/update/delete.
There is already one solution available on the forums which includes the use of lifecycle events (PostLoad(), PreRemove() and PreStore() using IInstanceCallbacks) but the problem with it is that every entity class would need to have these methods and this can be quite time consuming. Also the old objects property values are not available and information about the type of modification action in case of inserting/updating is also unavailable (to my knowledge).
Since I dont have an indepth knowledge of OpenAccess (v. 2012.1.301.2) to be able to create such a mechanism on the fly and would probably waste way to much time any kind of pointers and suggestions are most welcome.
Thanks
one of the requirements for a project we are currently developing is to audit changes of persistened objects. There are several different approaches to achieve this and writing database triggers is my final resolve if some sort of relatively simple automatic audit mechanism in OpenAccess cannot be implemented.
The most simple approach would be to either add custom audit logic to the DBContext.SaveChanges() or to catch modification events (Adding/Added etc.) and then audit changes there. The biggest problem is probably getting the old and the new values of the object and the entity type.
Basically the idea is to have all the audit logic in one place and when the object changes all the neccessary information about entity type and old object data are also available and used for writing an audit trail into database table.
Audit table currently looks like this:
AuditLogID
UserID
ObjectID
AuditTypeID
ObjectEntityName
OldData (XML)
NewData (XML)
AuditDate
The point is to save inserted/updated/deleted object into OldData and NewData columns which are XML. UserID is the ID of current user who is making the changes to the object(s). ObjectEntityName holds the name of the entity (basically table name). AuditTypeID is used for identifying the type of change ie. select/insert/update/delete.
There is already one solution available on the forums which includes the use of lifecycle events (PostLoad(), PreRemove() and PreStore() using IInstanceCallbacks) but the problem with it is that every entity class would need to have these methods and this can be quite time consuming. Also the old objects property values are not available and information about the type of modification action in case of inserting/updating is also unavailable (to my knowledge).
Since I dont have an indepth knowledge of OpenAccess (v. 2012.1.301.2) to be able to create such a mechanism on the fly and would probably waste way to much time any kind of pointers and suggestions are most welcome.
Thanks