|
|
Zverejnené 8. 8. 2016 13:17:51
|
|
|

1 Konfigurácia App.config:
<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <názov sekcie="hibernate-configuration" typ="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> <názov vlastnosti="connection.connection_string"> <!--Server=(lokálne); počiatočný katalóg=nhibernate; Integrovaná bezpečnosť=SSPI--> databáza='nhibernate'; server=.; uid='sa'; pwd='sa'; </property> <názov vlastnosti="adonet.batch_size">10</property> <názov vlastnosti="show_sql">pravda</property> <názov vlastnosti="dialect">NHibernate.Dialect.MsSql2005Dialect</property> <názov vlastnosti="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property> </session-factory> </hibernate-configuration> ----------------------------------------------------------------------------------------------------------------------
#region 2 。 App.config configuration Configuration config = nová Configuration(). AddAssembly("Test.Model");
factory = konfigurácia. BuildSessionFactory(); Session = továreň. OpenSession(); #endregion
-------------------------------------------------------------------------------------------------------------------------- </configuration>
2 Konfigurácia Web.config Zaznamenajte pozíciu bajtu, ktorá má byť umiestnená
<!--NHibernate --> <názov sekcie="hibernate-configuration" typ="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> <názov vlastnosti="dialect">NHibernate.Dialect.MsSql2005Dialect</property> <názov vlastnosti="connection.connection_string">database='nhibernate'; server=.; uid='sa'; pwd='sa'; </property> <názov vlastnosti="show_sql">pravda</property> <názov vlastnosti="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property> </session-factory> </hibernate-configuration> <!--NHibernate--> <appSettings/>
---------------------------------------------------------------------------------------------------------
#region 2. Použite web.config na konfiguráciu cez
NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration(). AddAssembly("Test.Model"); factory = konfigurácia. BuildSessionFactory(); Session = továreň. OpenSession();
#endregion
-----------------------------------------------------------------------------------------------------------
Konfigurácia 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"> <!-- vlastnosti --> <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property> <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property> <názov vlastnosti="dialect">NHibernate.Dialect.MsSql2005Dialect</property> <názov vlastnosti="connection.connection_string">database='nhibernate'; server=.; uid='sa'; pwd='sa'; </property> <názov vlastnosti="show_sql">pravda</property> <názov vlastnosti="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property> <názov vlastnosti="use_outer_join">pravda</property> <!-- mapovacie súbory --> <mapovanie zostavy="Test.Model" /> </session-factory> </hibernate-configuration>
-------------------------------------------------------------------------------------------------------------------------------------- -----------------------------------------------------------------------------------------------------------------------------------------
#region 3. Využitie NHibernate.cfg.xml konfigurácie
NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration(); konfigurácia. Configure(@"C:\Documents and Settings\Administrator\Desktop\Text\NHibernateTest\WebSite1\NHibernate.cfg.xml"); factory = konfigurácia. BuildSessionFactory(); Session = továreň. OpenSession(); #endregion
4 Vytvorte MyConfiguration.cs štruktúru nasledovne:
public static NHibernate.Cfg.Configuration GetConfig() {
NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration(); konfigurácia. SetProperty("hibernate.connection.provider", "NHibernate.Connection.DriverConnectionProvider"); konfigurácia. SetProperty("hibernate.connection.driver_class", "NHibernate.Driver.SqlClientDriver"); konfigurácia. SetProperty("hibernate.connection.connection_string", "database='nhibernate'; server=.; uid='sa'; pwd='sa'; "); konfigurácia. SetProperty("hibernate.dialect", "NHibernate.Dialect.MsSql2005Dialect,NHibernate"); konfigurácia. SetProperty("hibernate.use_outer_join", "true"); konfigurácia. SetProperty("hibernate.show_sql", "false"); konfigurácia. SetProperty("proxyfactory.factory_class", "NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu"); konfigurácia. AddAssembly("Test.Model"); return config;
}
------------------------------------------------------------------------------------------------------------------------------
#region 4. Použite MyConfiguration.cs konfiguráciu
NHibernate.Cfg.Configuration config = MyConfiguration.GetConfig(); Použite MyConfiguration.cs factory = konfigurácia. BuildSessionFactory(); factory = MyConfiguration.GetConfig(). BuildSessionFactory(); Session = továreň. OpenSession(); #endregion |
Predchádzajúci:webapi:ObjectContent1类型未能序列化内容类型“application/xml; charset=ut...Budúci:Nedá sa prečítať konfiguračná sekcia "XXX", pretože chýba príkaz sekcie
|