【问题标题】:Fluent NHibernate - exception occurred during configurationFluent NHibernate - 配置期间发生异常
【发布时间】:2015-06-16 00:29:47
【问题描述】:

我正在使用带有外部“hibernate.cfg.xml”文件的 Fluent NHibernate。通过机器名称,例如“Environment.MachineName + “.cfg.xml””

以下是出现错误的配置代码:

public static bool BuildSessionFactory()
        {
            if (_sessionFactory != null) return false;

        var configuration = new NHibernate.Cfg.Configuration();
        configuration.Configure(Environment.MachineName + ".cfg.xml");
        configuration.AddAssembly(System.Reflection.Assembly.GetExecutingAssembly());

        _sessionFactory = Fluently.Configure(configuration)
              .Mappings(m => m.FluentMappings.AddFromAssemblyOf<NHibernateHelper>())
              .BuildSessionFactory();

        return true;
    }

但是当 NHibernate 尝试配置时,我收到了以下错误:

异常说:

FluentNHibernate.Cfg.FluentConfigurationException was unhandled
Message: An unhandled exception of type 'FluentNHibernate.Cfg.FluentConfigurationException' occurred in FluentNHibernate.dll
Additional information: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.

【问题讨论】:

    标签: fluent-nhibernate


    【解决方案1】:

    当您的映射出现问题时会发生这种情况。主要的例外并没有告诉你更多。

    您需要深入查看内部异常的文本,然后通常应该非常清楚问题所在。

    编辑: 只是补充一点,虽然它没有任何问题,但在我看来,调用您的配置文件&lt;MachineName&gt;.cfg.xml 会为您的构建和部署过程增加不必要的复杂性。如果不重命名配置文件,您将无法将代码部署到另一台机器(例如测试或产品实例)。

    【讨论】:

    • 感谢您的回复,嗯,关于机器名称,这只是一个想法,您对映射的看法是正确的,谢谢
    • var Register = Fluently .Configure() .Database(MySQLConfiguration.Standard.ConnectionString(x => x .Server(Program.sqlhost) .Username(Program.sqlUsername) .Password(Program.sqlPassword) .Database(Program.sqlDatabase))) .Mappings(m => m.FluentMappings.AddFromAssemblyOf()) .BuildSessionFactory();
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-11
    • 2011-02-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多