Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have a requirement similar to yours. In my case, it's a health care application and the audit log needs to identify the patient to which the insert/update applies.</p> <p>My solution is to define an interface, which all audited classes need to implement :</p> <pre><code>public interface IAuditedRecord { IPatient OwningPatient { get; } ... // Other audit-related properties (user, timestamp) } </code></pre> <p>The audited classes then implement this interface in whatever way is required. For example:</p> <pre><code>public class Medication : IAuditedRecord { // One end of a bidirectional association. Populated by NHibernate. private IPatient _patient; IPatient OwningPatient { get { return _patient; } } } public class MedicationNote : IAuditedRecord { // One end of a bidirectional association. Populated by NHibernate. private Medication _medication; IPatient OwningPatient { get { return _medication.OwningPatient; } } } </code></pre> <p>The <code>IPostInsertEventListener</code> and <code>IPostUpdateEventListener</code> then fetch the <code>OwningPatient</code> property in order to populate the audit record.</p> <p>The solution has the advantages of keeping the auditing logic in the event listeners, which is the only place where one is sure that an insert/update will take place, as well as allowing the traversal of indirect links between an object and its owning patient.</p> <p>The downside is that the audited classes have to derive from a specific interface. I think the benefits outweigh this small cost.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload