この記事は機械翻訳のミラー記事です。元の記事にジャンプするにはこちらをクリックしてください。

眺める: 17312|答える: 0

[出典] .netにおけるNhibernateの設定方法は3つあります

[リンクをコピー]
掲載地 2016/08/08 13:17:51 | | |

1 App.config 設定:

<?XML Version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
    <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler,NHibernate" requirePermission="false"/>
</configSections>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" >
    <session-factory>
      <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider,NHibernate</property>
      <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
      <プロパティ名="connection.connection_string">
        <!--Server=(local); 初期カタログ=nhibernate; 統合セキュリティ=SSPI-->
        database='nhibernate'; server=.; uid='sa'; PWD='SA';
      </property>
      <プロパティ名="adonet.batch_size">10</property>
      <プロパティ名="show_sql">true</property>
      <プロパティ名="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
      <プロパティ名="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, nibernate.ByteCode.LinFu</property>
    </session-factory>
</hibernate-configuration>
----------------------------------------------------------------------------------------------------------------------

#region 2。 App.config 設定
            Configuration config = new Configuration(). AddAssembly("Test.Model");        

        factory = config。 BuildSessionFactory();
          セッション=工場。 OpenSession();
#endregion

--------------------------------------------------------------------------------------------------------------------------
</configuration>

2 Web.config Configuration 配置するバイト位置に注意

<!--ハブネート―->
   <セクション名="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate"/>
   <!--ハイバーネート――>
</configSections>
<!--ハイバーネート――>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
   <session-factory>
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
    <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
    <プロパティ名="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
    <プロパティ名="connection.connection_string">database='nhibernate'; server=.; uid='sa'; PWD='SA'; </property>
    <プロパティ名="show_sql">true</property>
    <プロパティ名="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, nibernate.ByteCode.LinFu</property>
   </session-factory>
</hibernate-configuration>
<!--ハイバーネート――>
<appSettings/>

---------------------------------------------------------------------------------------------------------



#region 2. web.configを使って設定してください。

        NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration(). AddAssembly("Test.Model");
        factory = config。 BuildSessionFactory();
        セッション=工場。 OpenSession();

        #endregion

-----------------------------------------------------------------------------------------------------------

3 NHibernate.cfg.xml構成:

<?XML Version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-mapping-2.2">
<session-factory xmlns="urn:nhibernate-configuration-2.2">
    <!--性質 -->
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
    <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
    <プロパティ名="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
    <プロパティ名="connection.connection_string">database='nhibernate'; server=.; uid='sa'; PWD='SA'; </property>
    <プロパティ名="show_sql">true</property>
     <プロパティ名="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, nibernate.ByteCode.LinFu</property>
    <プロパティ名="use_outer_join">true</property>
    <!--マッピングファイル -->
    <mapping assembly="Test.Model" />
</session-factory>
</hibernate-configuration>

-------------------------------------------------------------------------------------------------------------------------------------- -----------------------------------------------------------------------------------------------------------------------------------------

   #region 3. NHibernate.cfg.xml構成を活用する

        NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration();
        設定。 Configure(@"C:\Documents and Settings\Administrator\Desktop\Text\NHibernateTest\WebSite1\NHibernate.cfg.xml");
        factory = config。 BuildSessionFactory();
        セッション=工場。 OpenSession();
        #endregion



4 MyConfiguration.cs構造を次のように作成します:



public static NHibernate.Cfg.Configuration GetConfig()
    {

      
        NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration();
        設定。 SetProperty("hibernate.connection.provider", "NHibernate.Connection.DriverConnectionProvider");
        設定。 SetProperty("hibernate.connection.driver_class", "NHibernate.Driver.SqlClientDriver");
        設定。 SetProperty("hibernate.connection.connection_string", "database='nhibernate'; server=.; uid='sa'; PWD='SA'; ");
        設定。 SetProperty("hibernate.dialect", "nibernate.Dialect.MsSql2005Dialect, NHibernate");
        設定。 SetProperty("hibernate.use_outer_join"、「true」);
        設定。 SetProperty("hibernate.show_sql", "false");
        設定。 SetProperty("proxyfactory.factory_class", "nibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu");
        設定。 AddAssembly("Test.Model");
        設定を返す;
      
    }



------------------------------------------------------------------------------------------------------------------------------

#region 4. MyConfiguration.cs構成を使う

        NHibernate.Cfg.Configuration config = MyConfiguration.GetConfig(); Use MyConfiguration.cs
        factory = config。 BuildSessionFactory();
        factory = MyConfiguration.GetConfig(). BuildSessionFactory();
        セッション=工場。 OpenSession();
        #endregion




先の:webapi:ObjectContent1类型未能序列化内容类型“application/xml; charset=ut...
次に:構成セクション「XXX」はセクション文がないため読み取れません
免責事項:
Code Farmer Networkが発行するすべてのソフトウェア、プログラミング資料、記事は学習および研究目的のみを目的としています。 上記の内容は商業的または違法な目的で使用されてはならず、そうでなければ利用者はすべての結果を負うことになります。 このサイトの情報はインターネットからのものであり、著作権紛争はこのサイトとは関係ありません。 ダウンロード後24時間以内に上記の内容を完全にパソコンから削除してください。 もしこのプログラムを気に入ったら、正規のソフトウェアを支持し、登録を購入し、より良い本物のサービスを受けてください。 もし侵害があれば、メールでご連絡ください。

Mail To:help@itsvse.com