1 Διαμόρφωση App.config:
<?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> <όνομα ιδιότητας="connection.driver_class">NHibernate.Driver.SqlClientDriver</property> <όνομα ιδιότητας="connection.connection_string"> <!--Διακομιστής=(τοπικός); αρχικός κατάλογος=nhibernate; Ενσωματωμένη ασφάλεια=SSPI--> database='nhibernate'; διακομιστής=.; uid='sa'; pwd='sa'; </property> <όνομα ιδιότητας="adonet.batch_size">10</property> <όνομα ιδιότητας="show_sql">true</property> <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property> <όνομα ιδιότητας="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property> </session-factory> </hibernate-configuration> ----------------------------------------------------------------------------------------------------------------------
#region 2 。 Διαμόρφωση App.config Configuration config = new Configuration(). AddAssembly("Test.Model");
factory = διαμόρφωση. BuildSessionFactory(); συνεδρία = εργοστάσιο. OpenSession(); #endregion
-------------------------------------------------------------------------------------------------------------------------- </configuration>
2 Διαμόρφωση Web.config Σημειώστε τη θέση byte που θα τοποθετηθεί
<!--NHibernate --> <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, 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> <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property> <όνομα ιδιότητας="connection.connection_string">database='nhibernate'; διακομιστής=.; uid='sa'; pwd='sa'; </property> <όνομα ιδιότητας="show_sql">true</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 = νέο NHibernate.Cfg.Configuration(). AddAssembly("Test.Model"); factory = διαμόρφωση. 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> <property name="dialect">NHibernate.Dialect.MsSql2005Dialect</property> <όνομα ιδιότητας="connection.connection_string">database='nhibernate'; διακομιστής=.; uid='sa'; pwd='sa'; </property> <όνομα ιδιότητας="show_sql">true</property> <όνομα ιδιότητας="proxyfactory.factory_class">NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu</property> <όνομα ιδιότητας="use_outer_join">true</property> <!-- αρχεία χαρτογράφησης --> <mapping assembly="Test.Model" /> </session-factory> </hibernate-configuration>
-------------------------------------------------------------------------------------------------------------------------------------- -----------------------------------------------------------------------------------------------------------------------------------------
#region 3. Χρησιμοποιήστε NHibernate.cfg.xml διαμόρφωση
NHibernate.Cfg.Configuration config = νέο NHibernate.Cfg.Configuration(); config. Configure(@"C:\Documents and Settings\Administrator\Desktop\Text\NHibernateTest\WebSite1\NHibernate.cfg.xml"); factory = διαμόρφωση. BuildSessionFactory(); συνεδρία = εργοστάσιο. OpenSession(); #endregion
4 Δημιουργήστε μια δομή MyConfiguration.cs ως εξής:
δημόσιο στατικό NHibernate.Cfg.Configuration GetConfig() {
NHibernate.Cfg.Configuration config = νέο NHibernate.Cfg.Configuration(); config. SetProperty("hibernate.connection.provider", "NHibernate.Connection.DriverConnectionProvider"); config. SetProperty("hibernate.connection.driver_class", "NHibernate.Driver.SqlClientDriver"); config. SetProperty("hibernate.connection.connection_string", "database='nhibernate'; διακομιστής=.; uid='sa'; pwd='sa'; "); config. SetProperty("hibernate.dialect", "NHibernate.Dialect.MsSql2005Dialect,NHibernate"); config. SetProperty("hibernate.use_outer_join", "true"); config. SetProperty("hibernate.show_sql", "false"); config. SetProperty("proxyfactory.factory_class", "NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu"); config. AddAssembly("Test.Model"); διαμόρφωση επιστροφής?
}
------------------------------------------------------------------------------------------------------------------------------
#region 4. Χρησιμοποιήστε MyConfiguration.cs διαμόρφωση
NHibernate.Cfg.Configuration config = MyConfiguration.GetConfig(); Χρησιμοποιήστε MyConfiguration.cs factory = διαμόρφωση. BuildSessionFactory(); factory = MyConfiguration.GetConfig(). BuildSessionFactory(); συνεδρία = εργοστάσιο. OpenSession(); #endregion |