NPersistence - .NET Persistence API

Step 7 - Configure NPersistence

You are here

NPersistence is configured using an XML file called 'persistence.xml'. This file is marked as 'Embedded Resource'. 

  • Right click on the 'code' folder node, click 'Add New Item..'.
  • In the opened dialog choose 'XML File', name it 'persistence.xml' and click 'Add'.

  • Right click on the 'persistence.xml' file, click 'properties' - the properties view will open.
  • In the 'Build Action' property, set the property value to 'Embedded Resource'.
  • Open the 'persistence.xml' file and paste the following XML inside it.
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="" xmlns:xsi="" xsi:schemaLocation="">
  <persistence-unit name="webPersistenceUnit" transaction-type="RESOURCE_LOCAL">
      <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="" value="update"/>


  • 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.

Next: Step 8 - edit the web form