Jake Petroules
Jake Petroules

Reputation: 24190

Check constraints in NHibernate

Is there a way to have NHibernate's SchemaExport generate check constraints defined in its .hbm.xml files? Or is that not really part of its domain?

Either way, how can I, in combination with NHibernate's SchemaExport, add check constraints to the schema it generates so as to run my unit tests properly.

Upvotes: 2

Views: 1169

Answers (1)

csano
csano

Reputation: 13716

Yes. When you define your property mapping, you can define a column and identify a constraint via the check attribute.

<property name="count" not-null="true" >
  <column name="count" check="count &gt;= 0"/>
</property>

See Section 19.1 of the NHibernate documentation for more details.

Upvotes: 3

Related Questions