回滚Fluent NHibernate中PersistenceSpecifications创建的记录

Mat*_*nig 7 c# fluent-nhibernate

我正在学习一些Fluent NHibernate,而且我遇到过半熟的PersistenceSpecification类.

我已经在单元测试中进行了设置以验证我的映射,并且它运行良好.但是,它在完成后会将记录留在数据库中.我尝试在事务中抛出它,所以我可以回滚更改,但是我收到一个错误:

System.ObjectDisposedException:无法访问已处置的对象.对象名称:'AdoTransaction'..

如果没有事务,我必须弄清楚记录的ID,检索它们并删除它们,这看起来并不优雅.

有什么想法吗?

编辑:

这是代码片段:

            var factory = GetSessionFactory();
            using (var session = factory.OpenSession())
            using (var transaction = session.BeginTransaction())
            {
                new PersistenceSpecification<TimePeriod>(session)
                        .CheckProperty(x => x.EndDate, DateTime.Today)
                        .VerifyTheMappings();
                transaction.Rollback();
            }
Run Code Online (Sandbox Code Playgroud)

lee*_*ndt 9

尝试在事务上设置IsolationLevel.这个片段对我有用:

using (var trans = _session.BeginTransaction(IsolationLevel.ReadUncommitted))
{
    new PersistenceSpecification<Event>(_session)
        .CheckProperty(p => p.StartTime, new DateTime(2010, 1, 1))
        .VerifyTheMappings();
    trans.Rollback();
}
Run Code Online (Sandbox Code Playgroud)