Nhibernate Evers, how to change AuditJoinTable name

118 Views Asked by At

i'am using fluent Nhibernate and Envers with this setup

var enversConf = new NHibernate.Envers.Configuration.Fluent.FluentConfiguration();

        enversConf.Audit<Segnalazione>()            

        IRevisionListener revListner = services.GetService<IRevisionListener>();
        enversConf.SetRevisionEntity<RevisionEntity>(e => e.Id, e => e.RevisionDate, revListner);
        cfg.SetEnversProperty(ConfigurationKey.AuditTableSuffix, "_LOG");
        cfg.SetEnversProperty(ConfigurationKey.AuditStrategy, typeof(CustomValidityAuditStrategy));

        cfg.IntegrateWithEnvers(enversConf);

i need to change AuditJoinTable naming adding a prefix XXX_

All others table have same prefix and so standard logging table inherits it, only JoinTable hasn't it

i found settings for java version but not for .net one

EDIT: Now i have table with this naming convention:

XXX_Table1
XXX_Table2

main log table are create with _LOG suffix, so i get

XXX_Table1_LOG 
XXX_Table2_LOG 

while

AuditJoinTable are created as

Table1Table2_LOG 

and i need

XXX_Table1Table2_LOG 
2

There are 2 best solutions below

0
On BEST ANSWER

I am solving this by adding the name to each join table. Could be more generic but it works.

enversConf.Audit<Segnalazione>()
            .SetTableInfo(ug => ug.Foo, t => t.TableName = "XXX_Segnalazione_Foo")
4
On

Do you mean that cfg.SetEnversProperty(ConfigurationKey.AuditTablePrefix, "XXX_") doesn't work? It should.

IEnversNamingStrategy is used to decide names for tables, default this one is used where ConfigurationKey.AuditTablePrefix is used for "default prefix". You can also inject your own impl of this interface if you want to.

Using SetTableInfo overrides this and surely works but if I understand you correctly you don't need to do that in this case.