【问题标题】:SessionFactory Configure ErrorSessionFactory 配置错误
【发布时间】:2011-09-12 17:06:33
【问题描述】:

NHibernate。

我正在使用 sql compaq 版本,并且我有很多表,我需要为每个表制作 CRUDS(插入、更新、删除和获取)。

此时我遇到了 SessionFactory 类的问题。

目前我不知道是否需要编写所有类来进行组装。

私有静态ISessionFactory _sessionFactory;

    private static ISessionFactory SessionFactory
    {
        get 
        {
            if (_sessionFactory == null)
            {
                var configuration = new Configuration();
                configuration.Configure("hibernate.cfg.xml");

//在以下 3 行重复映射异常。


                configuration.AddAssembly(typeof(Employee).Assembly);
                configuration.AddAssembly(typeof(SetState).Assembly);
                configuration.AddAssembly(typeof(SetPriority).Assembly);

                _sessionFactory = configuration.BuildSessionFactory();
            }
            return _sessionFactory;
        }
    }

    public static ISession OpenSession() 
    {
        return SessionFactory.OpenSession();
    }

当我需要在许多表中工作时,如何配置它?

【问题讨论】:

    标签: hibernate nhibernate


    【解决方案1】:

    当你使用时

    configuration.AddAssembly(typeof(Employee).Assembly);
    

    您会自动添加程序集中包含的所有类和 hbm 文件,因此您只需要第一行并可以删除其他两行。

    【讨论】:

      猜你喜欢
      • 2017-02-10
      • 1970-01-01
      • 2014-07-18
      • 2015-12-31
      • 1970-01-01
      • 1970-01-01
      • 2016-09-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多