2016-07-27 4 views
0

NHibernate 3.3.3.4000で.net 4.5を使用しており、2つのセッションファクトリを使用してnhibernate.configを設定したいとします。 は、私は私のnhibernate.configこのよう形作ることを試みた:xセッションファクトリを使用したnhibernate設定

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"> 
    <session-factory name="Configuration"> 
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property> 
    <property name="connection.driver_class">NHibernate.Driver.SQLite20Driver</property> 
    <property name="connection.connection_string">Data Source=Configuration.db;Version=3</property> 
    <property name="dialect">NHibernate.Dialect.SQLiteDialect</property> 
    <property name="query.substitutions">true=1;false=0</property> 
    <property name="show_sql">false</property> 
    <mapping assembly="DataModel"/> 
    </session-factory> 
    <session-factory name="Texts"> 
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property> 
    <property name="connection.driver_class">NHibernate.Driver.SQLite20Driver</property> 
    <property name="connection.connection_string">Data Source=Texts.db;Version=3</property> 
    <property name="dialect">NHibernate.Dialect.SQLiteDialect</property> 
    <property name="query.substitutions">true=1;false=0</property> 
    <property name="show_sql">false</property> 
    <mapping assembly="DataModel_Texts"/> 
    </session-factory> 
</hibernate-configuration> 

をしかし、私は、「セッション・ファクトリー」は無効であるHibernateConfigExceptionを取得:名前空間の要素「休止状態-設定を」: 例外は、構成を解析発生しました'urn:nhibernate-configuration-2.2'は、名前空間 'urn:nhibernate-configuration-2.2'で無効な子要素 'session-factory'を持っています。

2つのセッションファクトリでファイルを設定する方法がありますか?

よろしく フィル

+0

NH4を.Net 4.5で使用する必要があります。 –

+0

これは本当に例外で得られる唯一の情報であり、InnerExceptionsがあればそのすべてですか? –

+0

多分この記事はあなたを助けることができます:http://www.codeproject.com/Articles/14846/Using-NHibernate-with-Multiple-Databases –

答えて

0

あなたはNHibernateの設定方法の拡張メソッドを提供NHibernate X-Factoriesを試してみてください。拡張メソッドを使用すると、構成ファイルから適切なセッションファクトリを選択するための名前を指定できます。

あり、最小限の設定があるが、あなたの設定ファイルは、次のようなものになります。セッションファクトリの設定

<hibernate-configuration-x-factories xmlns="urn:nhibernate-configuration-2.2-x-factories"> 
    <session-factory name="Configuration"> 
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property> 
    <property name="connection.driver_class">NHibernate.Driver.SQLite20Driver</property> 
    <property name="connection.connection_string">Data Source=Configuration.db;Version=3</property> 
    <property name="dialect">NHibernate.Dialect.SQLiteDialect</property> 
    <property name="query.substitutions">true=1;false=0</property> 
    <property name="show_sql">false</property> 
    <mapping assembly="DataModel"/> 
    </session-factory> 
    <session-factory name="Texts"> 
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property> 
    <property name="connection.driver_class">NHibernate.Driver.SQLite20Driver</property> 
    <property name="connection.connection_string">Data Source=Texts.db;Version=3</property> 
    <property name="dialect">NHibernate.Dialect.SQLiteDialect</property> 
    <property name="query.substitutions">true=1;false=0</property> 
    <property name="show_sql">false</property> 
    <mapping assembly="DataModel_Texts"/> 
    </session-factory> 
</hibernate-configuration-x-factories> 

は、以下の方法で行うことができる:

NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration(); 

config 
    .Configure(HostingEnvironment.MapPath("~/nhibernate.cfg.xml"), "Development") 
    .BuildSessionFactory(); 

ドキュメントに見つけることができますgithub repo

+0

ありがとうございました。これはよさそうだ – Phil

関連する問題