Fluent NHibernate中的HBM导出函数似乎不起作用。流利的NHibernate(1.2.0.712)导出映射到HBM不工作/不尊重约定
如果我打电话FluentMappingsContainer.ExportTo,生成的映射出来不正确的,我得到以下异常:
FluentNHibernate.Cfg.FluentConfigurationException: An invalid or incomplete configuration was used while creating a SessionFactory. Check PotentialReasons collection, and InnerException for more detail.
我的配置代码如下所示:
MsSqlConfiguration database = MsSqlConfiguration.MsSql2008
.ConnectionString(GetConnectionString())
.Cache(c => c
.UseQueryCache()
.UseSecondLevelCache()
.ProviderClass<SysCacheProvider>()
);
database.ShowSql();
FluentConfiguration config = Fluently.Configure()
.Database(database)
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<Entity>()
.Conventions.AddFromAssemblyOf<Entity>());
config.ExposeConfiguration(x =>
{
x.SetProperty("hbm2ddl.keywords", "auto-quote");
x.SetInterceptor(new ServiceInterceptor());
});
config.ExposeConfiguration(x => { x.SetProperty("current_session_context_class", "thread_static"); });
// Configure HBM export path, if configured:
var path = Service.Config.HbmExportPath;
if (!String.IsNullOrEmpty(path))
config.Mappings(m => m.FluentMappings.ExportTo(path));
// Build session factory:
_sessionFactory = config.BuildSessionFactory();
在设置HbmExportPath我配置为空,应用程序启动和运行没有问题。只要我配置了导出路径(导致调用ExportTo),生成的映射就会如上所述导致异常。
看看导出的映射,看来我的约定没有被应用 - 例如,我有一个外键约定,使用骆驼大小写和“Id”后缀,但是当我导出HBM文件时,主键始终与下划线和小写的“_id”命名,例如:
<class xmlns="urn:nhibernate-mapping-2.2" name="MyApp.Entities.Contact, MyApp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null" table="`Contact`">
...
<bag name="Departments" table="ContactDepartment">
<key>
<column name="Contact_id" />
</key>
<many-to-many class="MyApp.Entities.Department, MyApp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<column name="Department_id" />
</many-to-many>
</bag>
...
</class>
我有这个问题与以前的版本,并用流利的当前版本。
任何想法?
作者(詹姆斯格雷戈里)证实,这个功能很粗糙,需要一些工作。所以这种解决方法是现在的方式 - 我正在关闭这个线程,并希望这个答案对其他人有用。 –
谢谢,我刚开始看了一些导出的hbm.xml文件,我以为我疯了,想知道为什么我的表命名约定丢失了。这解决了我的问题! – dotjoe