R – Nhibernate – Generate schema without forign key

fluent-nhibernatenhibernate

For our test fixtures we use NHibernate to generate a database schema. We have a slight strange case in which an entity references a another entity but we don't wish to have a foreign key constraint (it should be possible to delete the referenced entity so a foreign key cannot be used).

Is it possible to specify that the generated schema does not have a foreign key for a particular relationship?

Best Answer

Jay-

If you're using Fluent NHibernate, you can set this in either your implementation of IHasManyConvention or IReferenceConvention (if using conventions).

Cascade.SaveUpdate() should propagate the saves and updates, but leave the orphaned child objects when the parents are deleted.

In standard NHibernate HBM files, I believe the tag for a bag should look like:

<bag cascade="save-update" name="EntityName"> ... </bag>

UPDATE: Here's an informational post by Ayende on the topic of orphaning child objects and the differences with the cascade values.

Related Topic