Disclaimer: I am an NHibernate noobie so hopefully this question makes sense. I have a many-to-many relationship between two classes something like…
public class Entity1
{
public virtual Guid EntityId { get; set; }
public virtual IList<Entity2> Entity2List;
}
Public class Entity2
{
public virtual Guid EntityId { get; set; }
public virtual IList<Entity1> Entity1List;
}
I’ve added a many-to-many relationship with a bag in both class mappings, defining an association table but am unsure of which cascade option to use. I want to be able to create a new Entity1 instance, add a new Entity2 instance to it’s list, call Save, and both be inserted into the database (and vice-versa). When deleting an entity it should delete any associations to child entities but not the child entity itself. Should I be using cascade="save-update"?
Yes. It sounds like 'save-update' is what you want, in this case.
I never found a great explanation of each cascade option in the documentation, but have used this blog post by Ayende as reference.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With