我有以下配置来设置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()
非常感谢任何帮助。