【发布时间】:2012-09-11 17:50:54
【问题描述】:
我有一个使用 NHibernate 的应用程序,并且我正在使用 Fluent NHibernate 来映射我的实体。它工作正常,但是,我想使用 NHibernate 的本地方式创建 SessionFactory,因为我的团队将在其他项目中使用这个库,所以我们需要这种灵活性来移动 nhibernate.cfg.xml。我的问题是:如何使用nhibernate的原生方式在SessionFactory的配置中设置Fluent Mappings?
我在我的配置方法上尝试这样的事情:
private static ISessionFactory Configure()
{
if (_factory != null)
return _factory;
var configuration = new Configuration().Configure();
// I could set my assembly of mapping here, but it's on our internal framework
var fluentConfiguration = Fluently.Configure(configuration)
//.Mappings(c => c.FluentMappings.AddFromAssembly(typeof(ProductMap)))
.BuildConfiguration();
_factory = fluentConfiguration.BuildSessionFactory();
return _factory;
}
我尝试通过xml设置,但是不行。
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<!-- other configs here...-->
<mapping assembly="MyApplication.Data.Mapping" />
</session-factory>
</hibernate-configuration>
我不知道是否有任何方法可以在 xml 上设置此映射并传递给我的方法上的 FluentConfiguration 声明以创建 ISessionFactory。
谢谢你们。
【问题讨论】:
标签: nhibernate orm fluent-nhibernate