Nhibernate Cannot delete the child object

Posted by Daoming Yang on Stack Overflow See other posts from Stack Overflow or by Daoming Yang
Published on 2012-06-25T20:13:35Z Indexed on 2012/06/25 21:16 UTC
Read the original article Hit count: 197

Filed under:
|

I know it has been asked for many times, i also have found a lot of answers on this website, but i just cannot get out this problem.

Can anyone help me with this piece of code?

Many thanks.

Here is my parent mapping file

<set name="ProductPictureList" table="[ProductPicture]" lazy="true" order-by="DateCreated" inverse="true" cascade="all-delete-orphan" >
  <key column="ProductID"/>
  <one-to-many class="ProductPicture"/>
</set>

Here is my child mapping file

<class name="ProductPicture" table="[ProductPicture]" lazy="true">
<id name="ProductPictureID">
  <generator class="identity" />
</id>
<property name="ProductID" type="Int32"></property>
<property name="PictureName" type="String"></property>
<property name="DateCreated" type="DateTime"></property>
</class>

Here is my c# code

        var item = _productRepository.Get(productID);

        var productPictrue = item.ProductPictureList
            .OfType<ProductPicture>()
            .Where(x => x.ProductPictureID == productPictureID);

        // reomve the finding item
        var ok =  item.ProductPictureList.Remove(productPictrue);

        _productRepository.SaveOrUpdate(item);

ok is false value and this child object is still in my database.

© Stack Overflow or respective owner

Related posts about nhibernate

Related posts about update