不知道我是否问正确的问题,请耐心等待我! NHibernate noob的位。流利NHibernate - HiLo计划的持久规范
我们正在使用流利的NH并具有以下ID生成方案的所有表
public class IdGenerationConvention : IIdConvention
{
public void Apply(IIdentityInstance instance)
{
var where = string.Format("TableKey = '{0}'", instance.EntityType.Name);
instance.GeneratedBy.HiLo("HiloPrimaryKeys", "NextHighValue", "1000", x => x.AddParam("where", where));
}
}
我们有一个生成的HiloPrimaryKeys
表,并与被部署期间运行数据的种子它的SQL脚本。这工作正常。
我现在正在尝试编写单元测试来验证我们的持久层,理想情况下在内存配置中使用SQLite来提高速度。这是我如何配置NH进行了检测:
[SetUp]
public void SetupContext()
{
config = new SQLiteConfiguration()
.InMemory()
.ShowSql()
.Raw("hibernate.generate_statistics", "true");
var nhConfig = Fluently.Configure()
.Database(PersistenceConfigurer)
.Mappings(mappings =>
mappings.FluentMappings.AddFromAssemblyOf<DocumentMap>()
.Conventions.AddFromAssemblyOf<IdGenerationConvention>());
SessionSource = new SessionSource(nhConfig);
Session = SessionSource.CreateSession();
SessionSource.BuildSchema(Session);
}
的问题是我不知道如何告诉NHibernate的有关我们的部署脚本,使其在测试过程中产生正确的架构和种子数据。
我得到的具体问题,运行以下PersistenceSpecification
测试时:
[Test]
public void ShouldAddDocumentToDatabaseWithSimpleValues()
{
new PersistenceSpecification<Document>(Session)
.CheckProperty(x => x.CreatedBy, "anonymous")
.CheckProperty(x => x.CreatedOn, new DateTime(1954, 12, 23))
.CheckProperty(x => x.Reference, "anonymous")
.CheckProperty(x => x.IsMigrated, true)
.CheckReference(x => x.DocumentType, documentType)
.VerifyTheMappings();
}
会抛出以下异常:
TestCase ... failed:
Execute
NHibernate.Exceptions.GenericADOException:
could not get or update next value[SQL: ]
---> System.Data.SQLite.SQLiteException: SQLite error
no such column: TableKey
所以我的推论是,它没有运行部署脚本当检查持久性规范时。
这种情况是否存在解决方案?我的谷歌似乎已经抛弃了这个。
是的,我尝试过,但似乎'PersistenceSpecification'只能在NH生成的模式下工作,而不是你可能做出的任何改变(据我所知) – 2011-04-16 09:27:40