请考虑以下内容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