Dieser Artikel ist ein Spiegelartikel der maschinellen Übersetzung, bitte klicken Sie hier, um zum Originalartikel zu springen.

Ansehen: 17312|Antwort: 0

[Quelle] Es gibt drei Konfigurationsmethoden für Nhibernate in .NET

[Link kopieren]
Veröffentlicht am 08.08.2016 13:17:51 | | |

1 App.config-Konfiguration:

<?xml version="1.0" Coding="utf-8" ?>
<configuration>
<configSections>
    <Abschnitt 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>
      <Eigenschaftsname="connection.connection_string">
        <!--Server=(lokal); Anfangskatalog=Nhibernat; Integrierte Sicherheit=SSPI-->
        datenbank='nhibernate'; server=.; uid='sa'; pwd='sa';
      </property>
      <Eigenschaftsname="adonet.batch_size">10</property>
      <Eigenschaftsname="show_sql">true</property>
      <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
      <property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property>
    </session-factory>
</hibernate-configuration>
----------------------------------------------------------------------------------------------------------------------

#region 2 。 App.config konfiguration
            Konfigurationskonfiguration = neue Konfiguration(). AddAssembly("Test.Model");        

        Factory = Konfiguration. BuildSessionFactory();
          Sitzung = Fabrik. OpenSession();
#endregion

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

2 Web.config-Konfiguration Beachten Sie die zu platzierende Byteposition

<!--NHibernate -->
   <Abschnitt Name="Hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate"/>
   <!--NHibernate-->
</configSections>
<!--NHibernate-->
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
   <session-factory>
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProviderProvider</property>
    <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
    <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
    <property name="connection.connection_string">database='nhibernate'; server=.; uid='sa'; pwd='sa'; </property>
    <Eigenschaftsname="show_sql">true</property>
    <property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property>
   </session-factory>
</hibernate-configuration>
<!--NHibernate-->
<appSettings/>

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



#region 2. Verwenden Sie web.config, um zu konfigurieren

        NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration(). AddAssembly("Test.Model");
        Factory = Konfiguration. BuildSessionFactory();
        Sitzung = Fabrik. OpenSession();

        #endregion

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

3 NHibernate.cfg.xml Konfiguration:

<?xml version="1.0" Coding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-mapping-2.2">
<session-factory xmlns="urn:nhibernate-configuration-2.2">
    <!-- Eigenschaften -->
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProviderProvider</property>
    <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
    <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property>
    <property name="connection.connection_string">database='nhibernate'; server=.; uid='sa'; pwd='sa'; </property>
    <Eigenschaftsname="show_sql">true</property>
     <property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property>
    <property name="use_outer_join">true</property>
    <!-- Mapping-Dateien -->
    <mapping assembly="Test.Model" />
</session-factory>
</hibernate-configuration>

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

   #region 3. Nutzen Sie NHibernate.cfg.xml Konfiguration

        NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration();
        Konfiguration. Konfigurieren(@"C:\Dokumente und Einstellungen\Administrator\Desktop\Text\NHibernateTest\WebSite1\NHibernate.cfg.xml");
        Factory = Konfiguration. BuildSessionFactory();
        Sitzung = Fabrik. OpenSession();
        #endregion



4 Erstellen Sie eine MyConfiguration.cs Struktur wie folgt:



public static NHibernate.Cfg.Configuration GetConfig()
    {

      
        NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration();
        Konfiguration. SetProperty("hibernate.connection.provider", "NHibernate.Connection.DriverConnectionProvider");
        Konfiguration. SetProperty("hibernate.connection.driver_class", "NHibernate.Driver.SqlClientDriver");
        Konfiguration. SetProperty("hibernate.connection.connection_string", "database='nhibernate'; server=.; uid='sa'; pwd='sa'; ");
        Konfiguration. SetProperty("hibernate.dialect", "NHibernate.Dialect.MsSql2005Dialect,NHibernate");
        Konfiguration. SetProperty("hibernate.use_outer_join", "true");
        Konfiguration. SetProperty("hibernate.show_sql", "false");
        Konfiguration. SetProperty("proxyfactory.factory_class", "NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu");
        Konfiguration. AddAssembly("Test.Model");
        Rückgabe der Konfiguration;
      
    }



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

#region 4. Verwenden Sie MyConfiguration.cs Konfiguration

        NHibernate.Cfg.Configuration config = MyConfiguration.GetConfig(); Nutzen Sie MyConfiguration.cs
        Factory = Konfiguration. BuildSessionFactory();
        factory = MyConfiguration.GetConfig(). BuildSessionFactory();
        Sitzung = Fabrik. OpenSession();
        #endregion




Vorhergehend:webapi:ObjectContent1类型未能序列化内容类型“application/xml; charset=ut...
Nächster:Ich kann den Konfigurationsabschnitt "XXX" nicht lesen, weil ihm die Abschnittsanweisung fehlt
Verzichtserklärung:
Alle von Code Farmer Network veröffentlichten Software, Programmiermaterialien oder Artikel dienen ausschließlich Lern- und Forschungszwecken; Die oben genannten Inhalte dürfen nicht für kommerzielle oder illegale Zwecke verwendet werden, andernfalls tragen die Nutzer alle Konsequenzen. Die Informationen auf dieser Seite stammen aus dem Internet, und Urheberrechtsstreitigkeiten haben nichts mit dieser Seite zu tun. Sie müssen die oben genannten Inhalte innerhalb von 24 Stunden nach dem Download vollständig von Ihrem Computer löschen. Wenn Ihnen das Programm gefällt, unterstützen Sie bitte echte Software, kaufen Sie die Registrierung und erhalten Sie bessere echte Dienstleistungen. Falls es eine Verletzung gibt, kontaktieren Sie uns bitte per E-Mail.

Mail To:help@itsvse.com