Graviton
Graviton

Reputation: 83254

NHibernate: Make sure that the foreign key is not null

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:

Upvotes: 0

Views: 222

Answers (1)

Sly
Sly

Reputation: 15217

Probably you can try to set

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

Upvotes: 2

Related Questions