|
|
Julkaistu 8.8.2016 13.17.51
|
|
|

1 App.config-asetus:
<?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> <property name="connection.connection_string"> <!--Palvelin=(paikallinen); alkuperäinen katalogi=nhibernate; Integroitu turvallisuus=SSPI--> database='nhibernate'; server=.; uid='sa'; pwd='sa'; </property> <property name="adonet.batch_size">10</property> <property name="show_sql">true</property> <property name="murre">NHibernate.Dialect.MsSql2005Murre</property> <property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property> </session-factory> </hibernate-configuration> ----------------------------------------------------------------------------------------------------------------------
#region 2 。 App.config konfiguraatio Configuration config = new Configuration(). AddAssembly("Test.Model");
tehdas = konfiguraatio. BuildSessionFactory(); Sessio = tehdas. OpenSession(); #endregion
-------------------------------------------------------------------------------------------------------------------------- </configuration>
2 Web.config Asetus Huomaa tavun sijainti, johon sijoitetaan
<!--NHibernate --> <section 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.DriverConnectionProvider</property> <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property> <property name="murre">NHibernate.Dialect.MsSql2005Murre</property> <property name="connection.connection_string">database='nhibernate'; server=.; uid='sa'; pwd='sa'; </property> <property name="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. Käytä web.configia konfigurointiin
NHibernate.Cfg.Configuration config = uusi NHibernate.Cfg.Configuration(). AddAssembly("Test.Model"); tehdas = konfiguraatio. BuildSessionFactory(); Sessio = tehdas. OpenSession();
#endregion
-----------------------------------------------------------------------------------------------------------
3 NHibernate.cfg.xml Kokoonpano:
<?xml version="1.0" encoding="UTF-8" ?> <hibernate-configuration xmlns="urn:nhibernate-mapping-2.2"> <session-factory xmlns="urn:nhibernate-configuration-2.2"> <!-- ominaisuudet --> <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property> <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property> <property name="murre">NHibernate.Dialect.MsSql2005Murre</property> <property name="connection.connection_string">database='nhibernate'; server=.; uid='sa'; pwd='sa'; </property> <property name="show_sql">true</property> <property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property> <property name="use_outer_join">true</property> <!-- tiedostojen kartoitus --> <mapping assembly="Test.Model" /> </session-factory> </hibernate-configuration>
-------------------------------------------------------------------------------------------------------------------------------------- -----------------------------------------------------------------------------------------------------------------------------------------
#region 3. Hyödynnä NHibernate.cfg.xml konfiguraatiota
NHibernate.Cfg.Configuration config = uusi NHibernate.Cfg.Configuration(); konfiguraatio. Configure(@"C:\Documents and Settings\Administrator\Desktop\Text\NHibernateTest\WebSite1\NHibernate.cfg.xml"); tehdas = konfiguraatio. BuildSessionFactory(); Sessio = tehdas. OpenSession(); #endregion
4 Luo MyConfiguration.cs-rakenne seuraavasti:
public static NHibernate.Cfg.Configuration GetConfig() {
NHibernate.Cfg.Configuration config = uusi NHibernate.Cfg.Configuration(); konfiguraatio. SetProperty("hibernate.connection.provider", "NHibernate.Connection.DriverConnectionProvider"); konfiguraatio. SetProperty("hibernate.connection.driver_class", "NHibernate.Driver.SqlClientDriver"); konfiguraatio. SetProperty("hibernate.connection.connection_string", "database='nhibernate'; server=.; uid='sa'; pwd='sa'; "); konfiguraatio. SetProperty("hibernate.dialect", "NHibernate.Dialect.MsSql2005Dialect, NHibernate"); konfiguraatio. SetProperty("hibernate.use_outer_join", "tosi"); konfiguraatio. SetProperty("hibernate.show_sql", "väärin"); konfiguraatio. SetProperty("proxyfactory.factory_class", "NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu"); konfiguraatio. AddAssembly("Test.Model"); palautuskonfiguraatio;
}
------------------------------------------------------------------------------------------------------------------------------
#region 4. Käytä MyConfiguration.cs konfiguraatiota
NHibernate.Cfg.Configuration config = MyConfiguration.GetConfig(); Käytä MyConfiguration.cs tehdas = konfiguraatio. BuildSessionFactory(); factory = MyConfiguration.GetConfig(). BuildSessionFactory(); Sessio = tehdas. OpenSession(); #endregion |
Edellinen:webapi:ObjectContent1类型未能序列化内容类型“application/xml; charset=ut...Seuraava:En voi lukea konfiguraatiokohtaa "XXX", koska siitä puuttuu osiolause
|