我正在测试Fluent NH映射,我遇到了一个问题:
代码:
[TestMethod()]
public void FilterMapConstructorTest()
{
new PersistenceSpecification<Filter>(session)
.CheckProperty(c => c.Id, 1)
.CheckProperty(c => c.FilterValue, "1")
.CheckProperty(c => c.IdAttribute, 1)
.CheckProperty(c => c.Type, Filter.FilterType.Equals)
.VerifyTheMappings();
}
de compilator不会识别变量“session”,我应该声明这个,还是导入任何使用?
感谢你的时间。
最好的问候
答案 0 :(得分:0)
在使用它之前,您需要从会话工厂实际获得一个新的NHibernate会话。下面是一个更详细的例子:
ISessionFactory sessionFactory = Fluently.Configure(normalConfig)
.Mappings(m =>
m.FluentMappings
.AddFromAssemblyOf<Filter>())
.ProxyFactoryFactory("NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu")
.BuildSessionFactory();
using (NHibernate.ISession session = sessionFactory.OpenSession())
{
using (NHibernate.ITransaction tran = session.BeginTransaction(System.Data.IsolationLevel.ReadUncommitted))
{
new PersistenceSpecification<Filter>(session)
.CheckProperty(c => c.Id, 1)
.CheckProperty(c => c.FilterValue, "1")
.CheckProperty(c => c.IdAttribute, 1)
.CheckProperty(c => c.Type, Filter.FilterType.Equals)
.VerifyTheMappings();
tran.Rollback();
}
}