|
|
Публикувано в 8.08.2016 г. 13:17:51 ч.
|
|
|

1 App.config configuration:
<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <име на секция="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler,NHibernate" requirePermission="false"/> </configSections> <Hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" > <session-factory> <име на свойство="connection.provider">NHibernate.Connection.DriverConnectionProvider,NHibernate</property> <име на свойство="connection.driver_class">NHibernate.Driver.SqlClientDriver</property> <име на свойство="connection.connection_string"> <!--Сървър=(локален); initial catalog=nhibernate; Интегрирана сигурност=SSPI--> database='nhibernate'; сървър=.; uid='sa'; pwd='sa'; </property> <име на имот="adonet.batch_size">10</property> <име на свойство="show_sql">вярно</property> <име на свойство="диалект">NHibernate.Dialect.MsSql2005Диалект</property> <име на свойство="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property> </session-factory> </hibernate-configuration> ----------------------------------------------------------------------------------------------------------------------
#region 2 。 App.config configuration Конфигурация = нова конфигурация(). AddAssembly("Test.Model");
фабрика = конфигурация. BuildSessionFactory(); сесия = фабрика. OpenSession(); #endregion
-------------------------------------------------------------------------------------------------------------------------- </configuration>
2 Web.config Конфигурация Обърнете внимание на позицията на байта, която трябва да се постави
<!--NHibernate --> <име на секция="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandleler, NHibernate"/> <!--NHibernate--> </configSections> <!--NHibernate--> <Hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"> <session-factory> <име на свойство="connection.provider">NHibernate.Connection.DriverConnectionProvider</property> <име на свойство="connection.driver_class">NHibernate.Driver.SqlClientDriver</property> <име на свойство="диалект">NHibernate.Dialect.MsSql2005Диалект</property> <име на свойство="connection.connection_string">database='nhibernate'; сървър=.; uid='sa'; pwd='sa'; </property> <име на свойство="show_sql">вярно</property> <име на свойство="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property> </session-factory> </hibernate-configuration> <!--NHibernate--> <appSettings/>
---------------------------------------------------------------------------------------------------------
#region 2. Използвайте web.config за конфигуриране чрез
NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration(). AddAssembly("Test.Model"); фабрика = конфигурация. BuildSessionFactory(); сесия = фабрика. OpenSession();
#endregion
-----------------------------------------------------------------------------------------------------------
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"> <!-- свойства --> <име на свойство="connection.provider">NHibernate.Connection.DriverConnectionProvider</property> <име на свойство="connection.driver_class">NHibernate.Driver.SqlClientDriver</property> <име на свойство="диалект">NHibernate.Dialect.MsSql2005Диалект</property> <име на свойство="connection.connection_string">database='nhibernate'; сървър=.; uid='sa'; pwd='sa'; </property> <име на свойство="show_sql">вярно</property> <име на свойство="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property> <име на свойство="use_outer_join">вярно</property> <!-- файлове за картографиране --> <mapping assembly="Test.Model" /> </session-factory> </hibernate-configuration>
-------------------------------------------------------------------------------------------------------------------------------------- -----------------------------------------------------------------------------------------------------------------------------------------
#region 3. Използвайте NHibernate.cfg.xml конфигурация
NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration(); конфигурация. Configure(@"C:\Documents and Settings\Administrator\Desktop\Text\NHibernateTest\WebSite1\NHibernate.cfg.xml"); фабрика = конфигурация. BuildSessionFactory(); сесия = фабрика. OpenSession(); #endregion
4 Създайте MyConfiguration.cs структура по следния начин:
public static NHibernate.Cfg.Configuration GetConfig() {
NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration(); конфигурация. SetProperty("hibernate.connection.provider", "NHibernate.Connection.DriverConnectionProvider"); конфигурация. SetProperty("hibernate.connection.driver_class", "NHibernate.Driver.SqlClientDriver"); конфигурация. SetProperty("hibernate.connection.connection_string", "database='nhibernate'; сървър=.; uid='sa'; pwd='sa'; "); конфигурация. SetProperty ("хибернате.диалект", "NHibernate.Dialect.MsSql2005Dialect,NHibernate"); конфигурация. SetProperty("hibernate.use_outer_join", "true"); конфигурация. SetProperty ("hibernate.show_sql", "false"); конфигурация. SetProperty("proxyfactory.factory_class", "NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu"); конфигурация. AddAssembly("Test.Model"); конфигурация за връщане;
}
------------------------------------------------------------------------------------------------------------------------------
#region 4. Използвайте MyConfiguration.cs конфигурация
NHibernate.Cfg.Configuration config = MyConfiguration.GetConfig(); Използвайте MyConfiguration.cs фабрика = конфигурация. BuildSessionFactory(); factory = MyConfiguration.GetConfig(). BuildSessionFactory(); сесия = фабрика. OpenSession(); #endregion |
Предишен:webapi:ObjectContent1类型未能序列化内容类型“application/xml; charset=ut...Следващ:Не мога да прочета конфигурационната секция "XXX", защото липсва операторът на секцията
|