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
.
君たちありがとう。