I have two classes (Parent, Child) that have a many-to-many relationship that only one end (Parent) knows about. My problem is that when I delete a "relation unaware" object (Child), the record in the many-to-many table is left.
I want the relationship to be removed regardless of which end of it is deleted. How can I do that with Fluent NHibernate mappings, without adding a Parents property on Child?
The classes:
public class Parent
{
public Guid Id { get; set; }
public IList<Child> Children { get; set; }
}
public class Child
{
public Guid Id { get; set; }
// Don't want the property below:
// public IList<Parent> Parents { get; set; }
}
The many-to-many mapping for the Children property on Parent looks like this:
mapping.HasManyToMany(parent => parent.Children)
.LazyLoad();