I’m trying to enable my application to keep previous versions of entities.
For example, if I have a Book I want to be able to retrieve it at version 1, or at version 5, etc…
public class Book
{
public virtual int ID {get; set;}
public virtual string Name {get; set;}
public virtual int Version {get; set;}
}
I map the version column like this:
Version(x=>x.Version);
This is working. When it’s inserted, the version is 1.
If I pull back that entity by id, edit it, and save it, the version increments to 2.
My question is, how can I keep previous versions?
I’m suspecting some kind of composite on ID | Version…?
As Anton Gogolev pointed out – version property/column is not for auditing but for concurrency control.
NHibernate Envers is a 3rd party auditing lib for NHibernate that might suit your needs.