請考慮以下內容Fluent configuration;Fluent Nhibernate - ClassMaps in multiple,separate assemblies
FluentConfiguration config = Fluently.Configure();
config.Database(FluentNHibernate.Cfg.Db.MsSqlConfiguration.MsSql2008.ConnectionString(ConfigurationManager.ConnectionStrings[dbKey].ConnectionString));
// MemberMap is in the same assembly as this class, contains
// maps for member and role entities as part of a default
// membership service provider
MappingAssemblies.Add(typeof(MemberMap).Assembly);
foreach (Assembly mappingAssembly in MappingAssemblies)
{
// For each assembly that has been added to MappingAssemblies
// we add to the current mapping configuration. This allows
// me to drop this helper into any solution and it provide
// standardized membership abilities AS WELL AS manage
// the solutions unique ClassMaps
config.Mappings(m =>
m.FluentMappings.AddFromAssembly(mappingAssembly)
);
}
if (exportSchema)
{
config.ExposeConfiguration(cfg =>
{
new SchemaExport(cfg)
.Create(true, true);
}
);
}
_sessionFactory = config.BuildSessionFactory();
這個邏輯被保存在我的Global.asax應用程序啓動時調用的靜態類中。啓動配置看起來類似於;
Database.MappingAssemblies.Add(typeof(PageContentMap).Assembly);
// This is the method detailed above
Database.FluentConfigureSessionFactory("MySolutionsDb", true);
這樣的想法是,我打包我的會員和角色的實體對象到相同的組件設置爲數據庫輔助對象,這樣我關心創建可以立即獲得我的標準化成員的能力,以及能夠任何解決方案簡單地創建自己的特定於解決方案的ClassMaps並將其添加到配置對象中。
問題是,熟悉的電話;
config.Mappings(m =>
m.FluentMappings.AddFromAssembly(mappingAssembly)
);
似乎只能處理單個程序集。無論添加到列表中的是什麼,只添加最後一個程序集都會被映射。作爲上述的替代方案,我嘗試過參考MappingConfiguration
(這是'm'代表config.Mappings(m =>)
),但這也不起作用。很明顯,這樣一個m.FluentMappings.AddFromAssembly
或實際上任何FluentMappings.Add
方法的調用將覆蓋以前存在的內容,但肯定是有一種方法可以完成此任務嗎?這看起來不像是一個'怪異'的要求。
只是好奇,但你爲什麼要儲存了在不同的組件與一個數據庫實體?這並不是說這不是一個有效的問題,但又只是好奇而已。 –
您使用哪種版本的FNH?我記得有關於多個映射程序集的錯誤/限制 – Firo
@Cole W.因此,成員和角色實體對象來自與靜態數據庫類相同的程序集,但仍需要.AddAssemblyOf()調用。然後將其打包成一個.dll文件,並在我決定製定的新解決方案中引用。除了調用.AddAssemblyOf ()以將映射Member和Role對象到我的新解決方案數據庫之外,我還需要映射這個新解決方案中涉及的唯一實體對象;在上述成員和角色對象中,它們不在同一個程序集中。 –
user407356