Search code examples
c#sql-servernhibernateormnhibernate-mapping

How to get Nhibernate to rebuild Database?


Question

How can I force Nibernate to rebuild a database and add a new field when i add it in the mapping?

Currently it will only rebuild the table if i change the name of the table in the mapping XML.

My Mapping XML

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true" assembly="HibernateTest" namespace="HibernateTest.Models">
  <class name="Employee" table="Employee2" dynamic-update="true" xmlns="urn:nhibernate-mapping-2.2">
    <cache usage="read-write"/>
    <id name="Id" column="Id" type="int">
      <generator class="native" />
    </id>
    <property name="FirstName" />
    <property name="LastName" />
    <property name="Designation" />
    <property name="SecondDesignation" />
  </class>
</hibernate-mapping>

Solution

  • You need to use SchemaExport. You can see documentation here http://nhibernate.info/doc/nhibernate-reference/toolsetguide.html#toolsetguide-s1