Fluent many-to-many: Deleting one end does not remove the entry in the relation table

Posted by Kristoffer on Stack Overflow See other posts from Stack Overflow or by Kristoffer
Published on 2010-04-26T07:51:12Z Indexed on 2010/04/26 7:53 UTC
Read the original article Hit count: 254

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 Parent 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 Parent Parent { get; set; }
}

© Stack Overflow or respective owner

Related posts about fluent-nhibernate

Related posts about nhibernate-mapping