Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fluent NHibernate Cascade - Which side?

Tags:

In using Fluent NHibernate, I can't seem to find a good explanation of when you use the cascading option on the References side vs. the HasMany side.

What's the difference (if any) in mapping the following...

References(...).Cascade.All();

vs

HasMany(...).Cascade.All();

My question stems from a problem when saving a parent (root) entity. Once it's saved, I want to insure that all child objects are also persisted.

like image 978
Adam Avatar asked Apr 02 '11 15:04

Adam


People also ask

What is the difference between NHibernate and fluent NHibernate?

Fluent NHibernate offers an alternative to NHibernate's standard XML mapping files. Rather than writing XML documents, you write mappings in strongly typed C# code. This allows for easy refactoring, improved readability and more concise code.


1 Answers

You put the cascade on the side that you are saving.

If you save the parent and want to cascade to the children, put the cascade mapping on the parent.

like image 174
mathieu Avatar answered Sep 18 '22 13:09

mathieu