I'm experimenting with Envers. I've got it working okay, except that when it generated the audit table for my audited entity it made all the varchar columns length 1, rather than the length of the corresponding column in the base table.
Like so:
Object: dbo.COMPANY_ADDRESS_TB
Column | Type
-----------------------------
ID | int
COMPANY_ID | int
ADDRESS_SEQ_NUM | int
TYPE | varchar(40)
ATTN | varchar(40)
STREET1 | varchar(60)
STREET2 | varchar(60)
STREET3 | varchar(60)
CITY | varchar(40)
STATE | varchar(25)
ZIP | varchar(18)
COUNTRY | varchar(25)
TIMESTAMP | binary(8)
ACTIVE | int
and then
Object: dbo.COMPANY_ADDRESS_TB_AUD
Column | Type
------------------------------
ID | int
REV | int
REVTYPE | tinyint
REVEND | int
ADDRESS_SEQ_NUM | int
addressSeqNum_MOD | bit
TYPE | varchar(1)
addressType_MOD | bit
ATTN | varchar(1)
attn_MOD | bit
STREET1 | varchar(1)
street1_MOD | bit
STREET2 | varchar(1)
street2_MOD | bit
STREET3 | varchar(1)
street3_MOD | bit
CITY | varchar(1)
city_MOD | bit
STATE | varchar(1)
state_MOD | bit
ZIP | varchar(1)
zip_MOD | bit
COUNTRY | varchar(1)
country_MOD | bit
ACTIVE | int
active_MOD | bit
Of course I can change the lengths by hand, but if I start auditing a lot of entities that could get both tedious and error-prone. Here's the code that sets this up:
var properties = new Dictionary<string, string>();
properties[NHibernate.Cfg.Environment.Dialect] = "NHibernate.Dialect.MsSql2008Dialect";
properties[NHibernate.Cfg.Environment.ConnectionDriver] = "NHibernate.Driver.SqlClientDriver";
properties[NHibernate.Cfg.Environment.Hbm2ddlAuto] = "update";
properties[NHibernate.Cfg.Environment.FormatSql] = "true";
properties[NHibernate.Cfg.Environment.ShowSql] = "true";
properties[NHibernate.Cfg.Environment.ConnectionString] = "Data Source=localhost;Initial Catalog=OU_KASH;Integrated Security=True;Asynchronous Processing=true";
var cfg = new Configuration();
cfg.Configure()
.SetProperties(properties)
.AddAssembly(typeof(AliasTb).Assembly.FullName)
;
cfg.SetEnversProperty(ConfigurationKey.StoreDataAtDelete, true);
cfg.SetEnversProperty(ConfigurationKey.AuditStrategy, typeof(NHibernate.Envers.Strategy.ValidityAuditStrategy));
cfg.SetEnversProperty(ConfigurationKey.TrackEntitiesChangedInRevision, true);
cfg.SetEnversProperty(ConfigurationKey.GlobalWithModifiedFlag, true);
cfg.IntegrateWithEnvers(new AttributeConfiguration());
Any idea what I might be doing wrong?