1 App.config yapılandırması:
<?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"> <!--Sunucu=(yerel); ilk katalog=Nhibernate; Entegre Güvenlik=SSPI--> database='hibernate'; sunucu=.; uid='sa'; pwd='sa'; </property> <property name="adonet.batch_size">10</property> <property name="show_sql">true</property> <property name="diyalek">NHibernate.Dialect.MsSql2005Lehçe</property> <property name="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property> </session-factory> </hibernate-configuration> ----------------------------------------------------------------------------------------------------------------------
#region 2 。 App.config yapılandırması Yapılandırma yapılandırması = yeni Yapılandırma(). AddAssembly("Test.Model");
fabrika = yapılandırma. BuildSessionFactory(); oturum = fabrika. OpenSession(); #endregion
-------------------------------------------------------------------------------------------------------------------------- </configuration>
2 Web.config Yapılandırma Yerleştirilecek bayt konumuna dikkat edin
<!--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="diyalek">NHibernate.Dialect.MsSql2005Lehçe</property> <property name="connection.connection_string">database='nhibernate'; sunucu=.; 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. Web.config üzerinden yapılandırma için kullanın.
NHibernate.Cfg.Configuration config = new NHibernate.Cfg.Configuration(). AddAssembly("Test.Model"); fabrika = yapılandırma. BuildSessionFactory(); oturum = fabrika. OpenSession();
#endregion
-----------------------------------------------------------------------------------------------------------
3 NHibernate.cfg.xml Konfigürasyon:
<?xml version="1.0" encoding="utf-8" ?> <hibernate-configuration xmlns="urn:nhibernate-mapping-2.2"> <session-factory xmlns="urn:nhibernate-configuration-2.2"> <!-- özellikleri --> <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property> <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property> <property name="diyalek">NHibernate.Dialect.MsSql2005Lehçe</property> <property name="connection.connection_string">database='nhibernate'; sunucu=.; 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> <!-- eşleme dosyaları --> <mapping assembly="Test.Model" /> </session-factory> </hibernate-configuration>
-------------------------------------------------------------------------------------------------------------------------------------- -----------------------------------------------------------------------------------------------------------------------------------------
#region 3. NHibernate.cfg.xml yapılandırmayı kullanın
NHibernate.Cfg.Configuration config = yeni NHibernate.Cfg.Configuration(); yapılandırma. Configure(@"C:\Documents and Settings\Administrator\Desktop\Text\NHibernateTest\WebSite1\NHibernate.cfg.xml"); fabrika = yapılandırma. BuildSessionFactory(); oturum = fabrika. OpenSession(); #endregion
4 Aşağıdaki şekilde MyConfiguration.cs bir yapı oluşturun:
public static NHibernate.Cfg.Configuration GetConfig() {
NHibernate.Cfg.Configuration config = yeni NHibernate.Cfg.Configuration(); yapılandırma. SetProperty("hibernate.connection.provider", "NHibernate.Connection.DriverConnectionProvider"); yapılandırma. SetProperty("hibernate.connection.driver_class", "NHibernate.Driver.SqlClientDriver"); yapılandırma. SetProperty("hibernate.connection.connection_string", "database='nhibernate'; sunucu=.; uid='sa'; pwd='sa'; "); yapılandırma. SetProperty("hibernate.dialect", "NHibernate.Dialect.MsSql2005Dialect,NHibernate"); yapılandırma. SetProperty("hibernate.use_outer_join", "gerçek"); yapılandırma. SetProperty("hibernate.show_sql", "yanlış"); yapılandırma. SetProperty("proxyfactory.factory_class", "NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu"); yapılandırma. AddAssembly("Test.Model"); konfigürasyonu geri döndürmek;
}
------------------------------------------------------------------------------------------------------------------------------
#region 4. MyConfiguration.cs yapılandırmayı kullanın
NHibernate.Cfg.Configuration config = MyConfiguration.GetConfig(); Kullanın MyConfiguration.cs fabrika = yapılandırma. BuildSessionFactory(); factory = MyConfiguration.GetConfig(). BuildSessionFactory(); oturum = fabrika. OpenSession(); #endregion |