Can NHibernate be configured to remove children when their links are set to zero?

I heard that this can also be achieved with triggers, but I would rather not follow this road if I can. Now it seems that nulling references to child objects simply leaves them orphaned in the database, which is at least not ideal.

Thank!

+3
source share
2 answers

You can set the cascade parameter to remove orphans:

HasMany(x => x.Children).KeyColumn("ParentId").AsBag().Inverse()
    .Cascade.AllDeleteOrphan();

To do this, you need to remove the child from the parent collection and clear the session:

using (var txn = session.BeginTransaction())
{
    parent.Children.Remove(child);
    txn.Commit();
}
+7
source

Fluent.NH , , . -- , .

, , .

NHibernate

0

Source: https://habr.com/ru/post/1751215/


All Articles