开发者

Testing a Fluent NH mapping

I'm testing a Fluent NH mapping and I have a problem:

The code:

[TestMethod()]
        public void FilterMapConstructorTest()
        {
            n开发者_StackOverflow中文版ew 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 don't recognice the variable "session", I should declare this, or import any using?

Thank's for your time.

Best Regards


You need to actually get a new NHibernate session from your session factory before you can use it. Below is a more detailed example:

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();
        }
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜