|
|
Zveřejněno 08.08.2016 13:17:51
|
|
|

1 App.config konfigurace:
<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <název sekce="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ázev vlastnosti="connection.connection_string"> <!--Server=(lokální); počáteční katalog=nhibernate; Integrovaná bezpečnost=SSPI--> databáze='nhibernate'; server=.; uid='sa'; pwd='sa'; </property> <název vlastnosti="adonet.batch_size">10</property> <název vlastnosti="show_sql">pravda</property> <název vlastnosti="dialect">NHibernate.Dialect.MsSql2005Dialect</property> <název 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 = konfigurace. BuildSessionFactory(); Session = továrna. OpenSession(); #endregion
-------------------------------------------------------------------------------------------------------------------------- </configuration>
2 Konfigurace web.config Všimněte si pozice bajtu, která má být umístěna
<!--NHibernate --> <název sekce="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ázev vlastnosti="dialect">NHibernate.Dialect.MsSql2005Dialect</property> <název vlastnosti="connection.connection_string">database='nhibernate'; server=.; uid='sa'; pwd='sa'; </property> <název vlastnosti="show_sql">pravda</property> <název vlastnosti="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property> </session-factory> </hibernate-configuration> <!--NHibernate--> <appSettings/>
---------------------------------------------------------------------------------------------------------
#region 2. Použijte web.config pro konfiguraci přes
NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration(). AddAssembly("Test.Model"); factory = konfigurace. BuildSessionFactory(); Session = továrna. OpenSession();
#endregion
-----------------------------------------------------------------------------------------------------------
3 NHibernate.cfg.xml Konfigurace:
<?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ázev vlastnosti="dialect">NHibernate.Dialect.MsSql2005Dialect</property> <název vlastnosti="connection.connection_string">database='nhibernate'; server=.; uid='sa'; pwd='sa'; </property> <název vlastnosti="show_sql">pravda</property> <název vlastnosti="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property> <název vlastnosti="use_outer_join">pravda</property> <!-- mapovacích souborů --> <mapování assembl="Test.Model" /> </session-factory> </hibernate-configuration>
-------------------------------------------------------------------------------------------------------------------------------------- -----------------------------------------------------------------------------------------------------------------------------------------
#region 3. Využít NHibernate.cfg.xml konfiguraci
NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration(); konfigurace. Configure(@"C:\Documents and Settings\Administrator\Desktop\Text\NHibernateTest\WebSite1\NHibernate.cfg.xml"); factory = konfigurace. BuildSessionFactory(); Session = továrna. OpenSession(); #endregion
4 Vytvořte MyConfiguration.cs strukturu následovně:
public static NHibernate.Cfg.Configuration GetConfig() {
NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration(); konfigurace. SetProperty("hibernate.connection.provider", "NHibernate.Connection.DriverConnectionProvider"); konfigurace. SetProperty("hibernate.connection.driver_class", "NHibernate.Driver.SqlClientDriver"); konfigurace. SetProperty("hibernate.connection.connection_string", "database='nhibernate'; server=.; uid='sa'; pwd='sa'; "); konfigurace. SetProperty("hibernate.dialect", "NHibernate.Dialect.MsSql2005Dialect,NHibernate"); konfigurace. SetProperty("hibernate.use_outer_join", "true"); konfigurace. SetProperty("hibernate.show_sql", "false"); konfigurace. SetProperty("proxyfactory.factory_class", "NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu"); konfigurace. AddAssembly("Test.Model"); return config;
}
------------------------------------------------------------------------------------------------------------------------------
#region 4. Použijte MyConfiguration.cs konfiguraci
NHibernate.Cfg.Configuration config = MyConfiguration.GetConfig(); Použijte MyConfiguration.cs factory = konfigurace. BuildSessionFactory(); factory = MyConfiguration.GetConfig(). BuildSessionFactory(); Session = továrna. OpenSession(); #endregion |
Předchozí:webapi:ObjectContent1类型未能序列化内容类型“application/xml; charset=ut...Další:Nelze přečíst konfigurační sekci "XXX", protože chybí příkaz sekce
|