Dit artikel is een spiegelartikel van machinevertaling, klik hier om naar het oorspronkelijke artikel te gaan.

Bekijken: 17312|Antwoord: 0

[Bron] Er zijn drie configuratiemethoden voor Nhibernate in .net

[Link kopiëren]
Geplaatst op 08-08-2016 13:17:51 | | |

1 App.config-configuratie:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
    <sectienaam="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>
      <property name="connection.connection_string">
        <!--Server=(local); Initiële catalogus=Nhibernate; Geïntegreerde beveiliging=SSPI-->
        database='nhibernate'; server=.; uid='sa'; pwd='sa';
      </property>
      <property name="adonet.batch_size">10</property>
      <property name="show_sql">waar</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 configuratie
            Configuratieconfiguratie = nieuwe configuratie(). AddAssembly("Test.Model");        

        fabriek = configuratie. BuildSessionFactory();
          Sessie = fabriek. OpenSession();
#endregion

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

2 Web.config Configuratie Let op de bytepositie die geplaatst moet worden

<!--NHibernate -->
   <sectienaam="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>
    <property name="show_sql">waar</property>
    <property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property>
   </session-factory>
</hibernate-configuration>
<!--NHibernate-->
<appSettings/>

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



#region 2. Gebruik web.config om te configureren

        NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration(). AddAssembly("Test.Model");
        fabriek = configuratie. BuildSessionFactory();
        Sessie = fabriek. OpenSession();

        #endregion

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

3 NHibernate.cfg.xml configuratie:

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-configuration xmlns="urn:nhibernate-mapping-2.2">
<session-factory xmlns="urn:nhibernate-configuration-2.2">
    <!-- eigenschappen -->
    <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>
    <property name="show_sql">waar</property>
     <property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property>
    <property name="use_outer_join">waar</property>
    <!-- mappingbestanden -->
    <mapping assembly="Test.Model" />
</session-factory>
</hibernate-configuration>

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

   #region 3. Maak gebruik van NHibernate.cfg.xml configuratie

        NHibernate.Cfg.Configuration config = nieuwe NHibernate.Cfg.Configuration();
        configuratie. Configureer(@"C:\Documenten en Instellingen\Administrator\Desktop\Tekst\NHibernateTest\WebSite1\NHibernate.cfg.xml");
        fabriek = configuratie. BuildSessionFactory();
        Sessie = fabriek. OpenSession();
        #endregion



4 Stel een MyConfiguration.cs structuur op als volgt:



publieke statische NHibernate.Cfg.Configuration GetConfig()
    {

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



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

#region 4. Gebruik MyConfiguration.cs configuratie

        NHibernate.Cfg.Configuration config = MyConfiguration.GetConfig(); Gebruik MyConfiguration.cs
        fabriek = configuratie. BuildSessionFactory();
        factory = MyConfiguration.GetConfig(). BuildSessionFactory();
        Sessie = fabriek. OpenSession();
        #endregion




Vorig:webapi:ObjectContent1类型未能序列化内容类型“application/xml; charset=ut...
Volgend:Kan de configuratiesectie "XXX" niet lezen omdat de sectie-instructie ontbreekt
Disclaimer:
Alle software, programmeermaterialen of artikelen die door Code Farmer Network worden gepubliceerd, zijn uitsluitend bedoeld voor leer- en onderzoeksdoeleinden; De bovenstaande inhoud mag niet worden gebruikt voor commerciële of illegale doeleinden, anders dragen gebruikers alle gevolgen. De informatie op deze site komt van het internet, en auteursrechtconflicten hebben niets met deze site te maken. Je moet bovenstaande inhoud volledig van je computer verwijderen binnen 24 uur na het downloaden. Als je het programma leuk vindt, steun dan de echte software, koop registratie en krijg betere echte diensten. Als er sprake is van een inbreuk, neem dan contact met ons op via e-mail.

Mail To:help@itsvse.com