Hello,

I got a little problem. I try to create a database schema for the
following problem.
I got a table "TreeNode" which describe a Tree with parent and
children and it works really well, If I delete a Parent all children
are deleted too. Now I have another table "Music" which saves music
items referenced to a single TreeNode. The mapping file for the music
table works just fine until I want to delete a TreeNode that is
referenced in the Music table, I get a
System.Data.SqlServerCe.SqlCeException (I use SQL Server compact
edition 3.5 as database) that the primary key can't be deleted because
it is still referenced. I thought I could tell Nhibernate through the
mapping files to delete all referenced rows with the cascade="all"
thing. After some tries to get it right I don't know what to do
anymore.

-----TreeNode.hbm.xml
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                   assembly="m3.data"
                   namespace="m3.data.Domains">

  <class name="TreeNode" >
    <id name="nodeId" >
      <generator class="guid" />
    </id>
    <property name="nodeName" unique="true"/>
    <property name="path" />
    <many-to-one name="parentNode" class="TreeNode"
column="parentNode" />

    <set name="Children" cascade="all-delete-orphan" >
      <key column="parentNode" foreign-key="fk_TreeNode_ParentNode" />
      <one-to-many class="TreeNode" />
    </set>
  </class>
</hibernate-mapping>

-----Music.hbm.xml
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                   assembly="m3.data"
                   namespace="m3.data.Domains">

  <class name="Music">
    <id name="musicId">
      <generator class="guid" />
    </id>
    <property name="title" />
    <property name="fileName" />
    <property name="artist" />
    <property name="length" />
    <property name="rating" />
    <property name="album" />
    <property name="year" />
    <property name="titleNumber" />
    <property name="genre" />
    <property name="commentary" />
    <property name="bitrate" />
    <property name="listened" />
    <many-to-one name="treeNode" class="TreeNode" column="nodeId" />
  </class>
</hibernate-mapping>

How can I tell nhibernate to delete all music items when the parent
TreeNode is deleted?
Thank you.

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to