Fluent nhibernate Fluent NHibernate-配置期间发生异常

Fluent nhibernate Fluent NHibernate-配置期间发生异常,fluent-nhibernate,Fluent Nhibernate,我正在使用Fluent NHibernate和一个外部“hibernate.cfg.xml”文件。按计算机名称,如“Environment.MachineName+”.cfg.xml“ 以下是出现错误的配置代码: public static bool BuildSessionFactory() { if (_sessionFactory != null) return false; var configuration = new NHib

我正在使用Fluent NHibernate和一个外部“hibernate.cfg.xml”文件。按计算机名称,如“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;
    }

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

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


Edit:我只是想添加,虽然它没有什么问题,但我认为调用配置文件
.cfg.xml
会给构建和部署过程增加不必要的复杂性。如果不重命名配置文件,您将无法将代码部署到另一台计算机(例如,测试或产品实例)

谢谢你的回复,关于机器名,这只是一个想法,关于映射thanksvar Register=fluntly.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();
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.