NH と Envers を設定するには、次の構成を使用します。
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());
var factory = cfg.BuildSessionFactory();
私がオフにする場合
cfg.SetEnversProperty(ConfigurationKey.AuditStrategy, typeof(NHibernate.Envers.Strategy.ValidityAuditStrategy));
正常に動作しますが、そのオプションを使用すると、トランザクションをコミットするときに次の例外が発生します (これにより、CompanyAddressTb オブジェクトが更新されます)。
ERROR NHibernate.AssertionFailure - An AssertionFailure occurred - this may indicate a bug in NHibernate or in your custom types.
System.InvalidOperationException: Cannot find previous revision for entity NhDoodling.Entities.Domain.CompanyAddressTb_AUD and id 12962904
at NHibernate.Envers.Strategy.ValidityAuditStrategy.updateLastRevision(ISession session, AuditConfiguration auditCfg, IList l, Object id, String auditedEntityName, Object revision, Boolean throwIfNotOneEntry)
at NHibernate.Envers.Strategy.ValidityAuditStrategy.Perform(ISession session, String entityName, Object id, Object data, Object revision)
at NHibernate.Envers.Synchronization.Work.AbstractAuditWorkUnit.Perform(ISession session, Object revisionData)
at NHibernate.Envers.Synchronization.AuditProcess.executeInSession(ISession executeSession)
at NHibernate.Envers.Synchronization.AuditProcess.DoBeforeTransactionCompletion()
at NHibernate.Envers.Synchronization.AuditProcessManager.<>c__DisplayClass4.<Get>b__0()
at NHibernate.Engine.ActionQueue.BeforeTransactionCompletionProcessQueue.BeforeTransactionCompletion()
どんな助けでも大歓迎です。