Alex
Alex

Reputation: 38519

Storing previous versions with parent entity using nhibernate envers

I'm using nhibernate envers to audit my data / save previous versions.

What I'd like to do is store previous versions against the parent entity.
Something like this:

public abstract class BookBase
{
    public virtual int ID { get; set; }
    public virtual string Name { get; set; }
    public virtual string Author { get; set; }
}

public class Book : BookBase
{
    public virtual ICollection<BookRevision> PreviousVersions { get; set; }
}

public class BookRevision : BookBase
{
    public virtual int VersionNumber { get; set; }
    public virtual DateTime VersionTimeStamp { get; set; }
}

Is that possible with envers nhibernate (using fluent nHibernate for mappings)
What would my envers config need to look like?
What would my mappings need to look like?

Upvotes: 1

Views: 556

Answers (1)

Roger
Roger

Reputation: 1950

Envers handles auditing for you, you don't have to define your own auditing types in your domain model.

Define (and map it as normal) your entity

public class Book
{
    public virtual int ID { get; set; }
    public virtual string Name { get; set; }
    public virtual string Author { get; set; }
}

If you want to do auditing on Book modifications, configure Envers like this

var enversCfg = new FluentConfiguration();
enversCfg.Audit<Book>();
yourNhCoreConfiguration.IntegrateWithEnvers(enversCfg);

Upvotes: 1

Related Questions