Fluent NHibernate - 配置期间发生异常
Fluent NHibernate - exception occurred during configuration
我正在将 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;
}
但是当 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.
当您的映射出现问题时会发生这种情况。主要异常并没有告诉你更多信息。
你需要深入查看内部异常的文本,然后通常应该很清楚问题是什么。
编辑: 只是补充一下,虽然没有任何问题,但我认为调用您的配置文件 <MachineName>.cfg.xml
会给您的构建和部署过程增加不必要的复杂性.如果不重命名配置文件,您将无法将代码部署到另一台机器(例如测试或产品实例)。
我正在将 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;
}
但是当 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.
当您的映射出现问题时会发生这种情况。主要异常并没有告诉你更多信息。
你需要深入查看内部异常的文本,然后通常应该很清楚问题是什么。
编辑: 只是补充一下,虽然没有任何问题,但我认为调用您的配置文件 <MachineName>.cfg.xml
会给您的构建和部署过程增加不必要的复杂性.如果不重命名配置文件,您将无法将代码部署到另一台机器(例如测试或产品实例)。