tags:

views:

61

answers:

1

Is there anyway to make sure that when I export schema in NHibernate, I can make sure some of the columns must not be null?

For example, in the below case, the column Doc_ID in ReuploadTable must not be null:

<class name="Test.Generated.BusinessObjects.DocumentStore, DAL" table="document_store" lazy="true">
 <id name="Id" column="Id">
   <generator class="native" />
 </id>
 <bag name="ReuploadTables" lazy="true" cascade="all-delete-orphan" inverse="true" >
  <key column="Doc_ID"></key>
  <one-to-many class="ReuploadTable"></one-to-many>
 </bag>
</class>

<class name="Test.Generated.BusinessObjects.ReuploadTable, DAL" table="reupload_table" lazy="true">
 <id name="Id" column="ID">
   <generator class="native" />
 </id>
 <property name="ReuploadTimes" column="ReuploadTimes" />
 <property name="FilePath" column="FilePath" />
 <many-to-one name="DocumentStore" column="Doc_ID" class="DocumentStore" />
</class>

And this is how I do the insertion:

+1  A: 

Probably you can try to set

<key column="Doc_ID" not-null="true"></key>
Sly