Having tried several solutions to get NHibernate to delete orphan records. Given the following structure:
public class Parent {
public virtual ICollection<Domain> Domains {get;set;}
}
public class Domain{
public virtual Parent Parent {get;set;}
}
UPDATE: It had nothing to do with the setter. This caused something else to go wrong which was fixed. But the deletion of orphans still does not happen I have tried the following:
Add an attribute on Domains (and on the Parent property of the Domain class) according to http://mookid.dk/oncode/archives/643
Added Automapping like:
AutoMap.Override<Parent>(map => { map.HasMany(x => x.Domains).Inverse().Cascade.All(); })
AutoMap.Override<Parent>(map => { map.HasMany(x => x.Domains).Cascade.All(); })
Both caused the Domain records to be stored with Parent_Id = null.
Is there any good example on how to achieve this in combination with Automapping?
you do not have specified deleteOrphan
map.HasMany(x => x.Domains).Inverse().Cascade.AllDeleteOrphan()