views:

281

answers:

0

I have 3 tables:

Media Selectionlist

and then an intermediate table for saving media that are in a certain selectionlist called selectionlist_mediamembers.

I have mapped them as following:

Media.xml

<bag name="SelectionlistMediamembers" lazy="true" cascade="all-delete-orphan" inverse="true" where="deleted = 0" >
      <key column="media"></key>
      <one-to-many class="SelectionlistMediamember"></one-to-many>
     </bag>

SelectionlistMediaMembers:

<many-to-one name="Media" column="media" class="Media"/>
     <many-to-one name="Selectionlist" column="selectionlist" class="Selectionlist"/>

And selectionlist.xml:

<bag name="SelectionlistMediamembers" lazy="true" cascade="all-delete-orphan" inverse="true" where="deleted = 0" >
      <key column="selectionlist"></key>
      <one-to-many class="SelectionlistMediamember"></one-to-many>
     </bag>

Now i keep on getting "Deleted object would be re-saved by cascade (remove deleted object from associations)"

When running the following code:

try
                    {

                        Debug.WriteLine("Removing from media");
                        //oMedia.SelectionlistMediamembers.Remove(oSelectionlistMediaMemberToDelete);
                        oSelectionlistMediaMemberToDelete.Media.SelectionlistMediamembers.Remove(oSelectionlistMediaMemberToDelete);
                        oSelectionlistMediaMemberToDelete.Media = null;
                        oSelectionlistMediaMemberToDelete.Selectionlist.SelectionlistMediamembers.Remove(oSelectionlistMediaMemberToDelete);
                        oSelectionlistMediaMemberToDelete.Selectionlist = null;
                        Debug.WriteLine("Deleting");
                        oMediaManager.Session.GetISession().Delete(oSelectionlistMediaMemberToDelete);
                        Debug.WriteLine("Updating Stuff");

                       oMediaManager.Session.GetISession().Save(Selectionlist);
                       oMediaManager.Session.GetISession().Save(oMedia);
                        //Debug.WriteLine("Flushing Session");
                        oMediaManager.Session.GetISession().Flush();

                                BtnSearch_Click(null, null);



                    }
                    catch (Exception ex)
                    {

                        MessageBox.Show(ex.ToString());
                        //throw;
                    }

I really don't get what i am doing wrong here..