I have two entities:
Code:
class Entity1
{
...
public virtual IList<Entity2> E2List{ get; set; }
...
}
class Entity2
{
...
public virtual IList<Entity1> E1List{ get; set; }
...
}
They should be connection using bidirectional many-to-many. This is mappings:
Code:
<class name="Entity1"....
<bag name="E2List" lazy="false" cascade="none" table="Entity1_Entity2" inverse="true">
<key><column name="Entity1Id" not-null="true" /></key>
<many-to-many class="Entity2" column="Entity2Id"/>
</bag>
</class>
<class name="Entity2"....
<bag name="E1List" lazy="false" cascade="none" table="Entity1_Entity2" inverse="false">
<key><column name="Entity2Id" not-null="true" /></key>
<many-to-many class="Entity1" column="Entity1Id"/>
</bag>
</class>
I want the following behaviour:
1)When I delete Entity1Instance I want all records in Entity1_Entity2, which references Entity1Instance, be deleted.
2)And contrary: when I delete
Entity2Instance I want all records in Entity1_Entity2, which references Entity2Instance, be deleted.
I discovered that inverse attribute plays important role in this: if I set inverse="true" for Entity1 (as in example) I have 2nd behaviour and if I set inverse="true" for Entity2 I have 1st behaviour. So I can reproduce only 1st or 2nd behavoiur but not both.
Please help!