I have a very simple problem with nhibernate (I just started using it)
I have the following hbm mapping files :
<class name="Customer" table="Customers" lazy="false">
<id name="Id" column="CustomerId">
<generator class="native">
</id>
<property name="Name" />
<property name="Picture" type="BinaryBlob" />
<bag name="Orders" cascade="all-delete-orphan" lazy="false">
<key column="CustomerId" />
<one-to-many class="Order" />
</bag>
</class>
<class name="Order" table="Orders" lazy="false">
<id name="Id" column="OrderId">
<generator class="native">
</id>
<property name="Name" />
<property name="Picture" type="BinaryBlob" />
<bag name="Products" cascade="all-delete-orphan" lazy="false"
<key column="OrderId" />
<one-to-many class="Product" />
</bag>
</class>
<class name="Product" table="Products" lazy="false">
<id name="Id" column="ProductId">
<generator class="native">
</id>
<property name="Name" />
<property name="Picture" type="BinaryBlob" />
<property name="ProductStr" />
</class>
Customer class has an int id, string name, byte[] picture and IList of Orders.
Order class has an int id, string name, byte[] picture and IList of Products.
Product class has an int id, string name, byte[] picture, string productstr and int quantity (which I dont currently use)
Customer table has a customer id, name and picture(varbinary(max)).
Order has order id, name, picture and a customer id
Product has a product id, name, picture, productstr and order id.
The problem : When I delete a customer using session.Delete(csCustomer), it succesfuly deletes the entire customer from the db but it doesnt delete all of its orders. It only puts null in the customer id field in all of the orders of the deleted customer.
Anyone can find a problem with my configuration? I saw an example of using nhibernate where they saved a reference to the customer in the order class and a reference to order in the product class, is that something I need to do to fix it?