Thanks for the answer! But still I cant´t get it to work..
With the code below, only the contact is deleted from the main table.
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" namespace="Business" assembly="Business">
<class name="Business.Contact, Business" table="Contact" >
<id name="Id" column ="id" type="System.Int32" >
<generator class="native" />
</id>
<property name="FirstName" />
<property name="LastName"/>
<property name="EMail"/>
<property name="TelePhone"/>
<property name="UserName"/>
<property name="Picture" type="BinaryBlob"/>
<bag name="Groups" table="GroupContact" inverse="true" lazy="true">
<key column="contactid" />
<many-to-many class="Business.Groups, Business" column="groupid" />
</bag>
</class>
</hibernate-mapping>
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" namespace="Business" assembly="Business">
<class name="Business.Groups" table="Groups">
<id name="GroupId" column="groupId" type="System.Int32">
<generator class="native" />
</id>
<property name="GroupName" type="String" />
<property name="UserName" type="String" />
<bag name="Contacts" table="GroupContact" cascade="delete" lazy="true">
<key column="groupid" />
<many-to-many class="Business.Contact, Business" column="contactid" />
</bag>
</class>
</hibernate-mapping>
In code I do this:
Contact p = (Contact)session.Load(typeof(Contact), Convert.ToInt32(contacts[i].ToString()));
session.Delete(p);
session.Flush();