tags:

views:

58

answers:

2

Should I use NHibernate Collection Cascading to perform collection save-updates, or should I use repositories to persist entity collection entities ?

+1  A: 

It does not usually make sense to enable cascade on a <many-to-one> or <many-to-many> association. Cascade is often useful for <one-to-one> and <one-to-many> associations.

If the child object's lifespan is bounded by the lifespan of the parent object, make it a life cycle object by specifying cascade="all-delete-orphan".

Otherwise, you might not need cascade at all. But if you think that you will often be working with the parent and children together in the same transaction, and you want to save yourself some typing, consider using cascade="persist,merge,save-update".

Lachlan Roche
A: 

Better look at code generator tools like My Generation,CodeSmith for NHibernate template.If you want to use My Generation then take a look at http://www.mygenerationsoftware.com/TemplateLibrary/User/?guid=06437130-d390-4145-8e86-ed9682ff444b template.Really good.

Wonde