25

What does Cascade in Nhibernate mean?

I see a lot of options in cascading:

  • Delete
  • All
  • AllDeleteOrphan
  • DeleteOrphan
  • SaveUpdate

Can you explain these with with examples and their distinctions?

Quintin Par
  • 15,862
  • 27
  • 93
  • 146

1 Answers1

28

It means apply the action to an item's related items.

Please see: NHibernate Cascades: the different between all, all-delete-orphans and save-update:

  • none - do not do any cascades, let users handle them by themselves.

  • save-update - when the object is saved/updated, check the associations and save/update any object that requires it (including save/update the associations in many-to-many scenario).

  • delete - when the object is deleted, delete all the objects in the association.

  • delete-orphan - when the object is deleted, delete all the objects in the association. In addition, when an object is removed from the association and not associated with another object (orphaned), also delete it.

  • all - when an object is save/update/delete, check the associations and save/update/delete all the objects found.

  • all-delete-orphan - when an object is save/update/delete, check the associations and save/update/delete all the objects found. In additional to that, when an object is removed from the association and not associated with another object (orphaned), also delete it.

Kiryl
  • 180
  • 13
Mitch Wheat
  • 295,962
  • 43
  • 465
  • 541
  • 1
    I don't understand the difference between all and all-delete-orphan could you please explain? – joncodo May 24 '12 at 14:19
  • 1
    @JonathanO if you choose all and then you remove an association it will only remove the association not the associated object. if you choose all-delete-orphan than it will remove associated object too. – iboware Jan 28 '13 at 12:57