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="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
  <persistence-unit name="testPersistenceUnit" transaction-type="RESOURCE_LOCAL">
    <provider>NPersistence.NHibernate.NHibernatePersistence</provider>
    <class>Hello_NPersistence.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>
</persistence>

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.

Next: Step 8 - edit the Main method