Jacko
Jacko

Reputation: 13195

check if NHibernate entity is contained in multiple entities

I would like to ensure that an entity is contained in at most one single entity. Is it possible to check this from the mapping files? In SQL land, I want to ensure that if a table has a foreign key, that there are no repeated entries in the foreign key column.

Thanks!

Jorge

Upvotes: 0

Views: 143

Answers (1)

Diego Mijelshon
Diego Mijelshon

Reputation: 52735

Just make the FK unique:

<many-to-one unique="true" />

Or, from the collection side:

<key>
  <column unique="true"/>
</key>

(I omitted all attributes non related to the problem)

Upvotes: 2

Related Questions