|
|
Közzétéve 2016. 08. 08. 13:17:51
|
|
|

1 App.config konfiguráció:
<?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"> <!--Szerver=(helyi); kezdeti katalógus=Nhibernate; Integrált biztonság=SSPI-> database='Nhibernate'; szerver=.; uid='sa'; pwd='sa'; </property> <property name="adonet.batch_size">10</property> <property name="show_sql">true</property> <property name="dialektus">NHibernate.Dialect.MsSql2005Dialektus</property> <property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property> </session-factory> </hibernate-configuration> ----------------------------------------------------------------------------------------------------------------------
#region 2 。 App.config konfiguráció Konfiguráció konfiguráció = új Konfiguráció(). AddAssembly("Test.Modell");
gyár = konfiguráció. BuildSessionFactory(); Session = gyár. OpenSession(); #endregion
-------------------------------------------------------------------------------------------------------------------------- </configuration>
2 Web.config konfiguráció Figyeld meg, melyik bájt pozíciót kell elhelyezni
<!--NHibernate --> <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate"/> <!--NHibernát--> </configSections> <!--NHibernát--> <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="dialektus">NHibernate.Dialect.MsSql2005Dialektus</property> <property name="connection.connection_string">database='nhibernate'; szerver=.; 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> <!--NHibernát--> <appSettings/>
---------------------------------------------------------------------------------------------------------
#region 2. Használd a web.config oldalt a konfiguráláshoz
NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration(). AddAssembly("Test.Modell"); gyár = konfiguráció. BuildSessionFactory(); Session = gyár. OpenSession();
#endregion
-----------------------------------------------------------------------------------------------------------
3 NHibernate.cfg.xml Konfiguráció:
<?xml version="1.0" encoding="utf-8" ?> <hibernate-configuration xmlns="urn:nhibernate-mapping-2.2"> <session-factory xmlns="urn:nhibernate-configuration-2.2"> <!-- tulajdonságok --> <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property> <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property> <property name="dialektus">NHibernate.Dialect.MsSql2005Dialektus</property> <property name="connection.connection_string">database='nhibernate'; szerver=.; 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> <!-- fájlok leképezése --> <mapping assembly="Test.Model" /> </session-factory> </hibernate-configuration>
-------------------------------------------------------------------------------------------------------------------------------------- -----------------------------------------------------------------------------------------------------------------------------------------
#region 3. Használd NHibernate.cfg.xml konfigurációt
NHibernate.Cfg.Configuration config = új NHibernate.Cfg.Configuration(); konfiguráció. Configure(@"C:\Documents and Settings\Administrator\Desktop\Text\NHibernateTest\WebSite1\NHibernate.cfg.xml"); gyár = konfiguráció. BuildSessionFactory(); Session = gyár. OpenSession(); #endregion
4 Hozz létre MyConfiguration.cs struktúrát az alábbiak szerint:
public static NHibernate.Cfg.Configuration GetConfig() {
NHibernate.Cfg.Configuration config = új NHibernate.Cfg.Configuration(); konfiguráció. SetProperty("hibernate.connection.provider", "NHibernate.Connection.DriverConnectionProvider"); konfiguráció. SetProperty("hibernate.connection.driver_class", "NHibernate.Driver.SqlClientDriver"); konfiguráció. SetProperty("hibernate.connection.connection_string", "database='nhibernate'; szerver=.; uid='sa'; pwd='sa'; "); konfiguráció. SetProperty("hibernate.dialect", "NHibernate.Dialect.MsSql2005Dialect,NHibernate"); konfiguráció. SetProperty("hibernate.use_outer_join", "true"); konfiguráció. SetProperty("hibernate.show_sql", "hamis"); konfiguráció. SetProperty("proxyfactory.factory_class", "NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu"); konfiguráció. AddAssembly("Test.Modell"); visszaküldési konfiguráció;
}
------------------------------------------------------------------------------------------------------------------------------
#region 4. Használd MyConfiguration.cs konfigurációt
NHibernate.Cfg.Configuration config = MyConfiguration.GetConfig(); Használd MyConfiguration.cs gyár = konfiguráció. BuildSessionFactory(); factory = MyConfiguration.GetConfig(). BuildSessionFactory(); Session = gyár. OpenSession(); #endregion |
Előző:webapi:ObjectContent1类型未能序列化内容类型“application/xml; charset=ut...Következő:Nem tudom olvasni a konfigurációs "XXX" szakaszt, mert hiányzik belőle a szakasz utasítás
|