In a web site, the persistence.xml configuration is embedded inside the web.config file.
- Open the ‘web.config’ file.
- Inside the ‘configuration’ tag, place the following XML
<configSections>
<section name="persistence-unit"
type="NPersistence.ConfigurationSectionHandler, NPersistence" />
</configSections>
<persistence-unit name="webPersistenceUnit" transaction-type="RESOURCE_LOCAL">
<provider>NPersistence.NHibernate.NHibernatePersistence</provider>
<class>Employee</class>
<properties>
<property name="connection.driver_class">NHibernate.Driver.MySqlDataDriver</property>
<property name="connection.connection_string">server=localhost; user id=user1; password=pass1; database=test2</property>
<property name="dialect">NHibernate.Dialect.MySQLDialect</property>
<property name="query.substitutions">true=1;false=0</property>
<property name="connection.provider" value="NHibernate.Connection.DriverConnectionProvider"/>
<property name="show_sql" value="true"/>
<property name="hbm2ddl.keywords" value="none"/>
<property name="hbm2ddl.auto" value="update"/>
</properties>
</persistence-unit>
Note:
- Change the content of 'connection.connection_string' to your DB configuration
- In the <class> tag, make sure that the persistent class name is correct and includes the namespace.
- Using the 'NPersistence.ConfigurationSectionHandler' is essential for NPersistence to be able to read the configuration.
Next: Step 8 - Edit the web form