测试 Fluent NH 映射

发布于 2024-11-24 00:51:13 字数 533 浏览 2 评论 0原文

我正在测试 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 编译器无法识别变量“session”,我应该声明它,还是导入任何 using?

感谢您抽出时间。

此致

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

The code:

[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 don't recognice the variable "session", I should declare this, or import any using?

Thank's for your time.

Best Regards

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无力看清 2024-12-01 00:51:13

在使用它之前,您实际上需要从会话工厂获取一个新的 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();
        }
    }

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();
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文