I have a project by NHibernate implementation and using Lazy Loading. I have two class in this project : Person and Family. Relation between Those two is aggregation, is mean a Person has a list of Person. Maping is :
<class name="Person" table="Person_Person" >
<id name="Id" type="Int64" unsaved-value="0">
<generator class="native" />
</id>
<bag name="Families" inverse="true" table="Person_Family" cascade="all-delete-orphan" >
<key column="Person_id_fk"/>
<one-to-many class="Domain.Entities.Family,Domain.Entities"/>
</bag>
</class>
In this project, I Get a person by ID then remove a family of families person.
Person person = SessionInstance.Get<Person>(id);
foreach (Family fam in person.Families)
if (fam.Name == "Jaun")
SessionInstance.Delete(fam);
The family not deleted, Because throw a exception by this message :
deleted object would be re-saved by cascade (remove deleted object from associations)[Domain.Entities.Family#167]
How can i delete a family of person?
person.Families.Remove(fam); SessionInstance.Save(person);
– Foothold