title: One to Many mapping not Cascading deletes
body: <p>I have a simple model where a <code>Player</code> may choose a unique <code>Selection</code> of integers which are saved in a <code>Selection</code> table</p>
  
  <p>Which looks like this</p>
  
  <pre><code>public class Player
  {
      private readonly ICollection&lt;Selection&gt; selection;
  
      public Player()
      {
          this.selection = new List&lt;Selection&gt;();
      }
  
      public virtual long Id { get; set; }    
      public virtual string Name { get; set; }
      public virtual string EmailAddress { get; set; }
  
      public virtual IEnumerable&lt;Selection&gt; Selection
      {
          get
          {
              return this.selection;
          }
      }
  
      public virtual void UpdateSelection(IEnumerable&lt;int&gt; balls)
      {
          this.selection.Clear();
          this.selection.AddRange(balls.Select(ball =&gt; new Selection { Player = this, Number = ball }));
      }
  }
  
  public class Selection
  {
      public virtual Player Player { get; set; }
      public virtual int Number { get; set; }
  }
  </code></pre>
  
  <p>This is what I'm using to map the selection to the player</p>
  
  <pre><code>this.Bag(
      x =&gt; x.Selection,
      m =&gt;
          {
              m.Key(k =&gt; k.Column("PlayerId"));
              m.Access(Accessor.Field);
              m.Cascade(Cascade.All);
              m.Inverse(true);
          },
      k =&gt; k.OneToMany());
  </code></pre>
  
  <p>And the selection map has a composed id</p>
  
  <pre><code>this.ComposedId(
      x =&gt;
          {
              x.Property(y =&gt; y.Number);
              x.ManyToOne(y =&gt; y.Player, m =&gt; m.ForeignKey("PlayerId"));
          });
  </code></pre>
  
  <p>As I change this list using the <code>UpdateSelection</code> method of <code>Player</code> then the <code>Selection</code> table should insert and delete rows where necessary.</p>
  
  <p>However, if I were to remove a number from the <code>Selection</code> when the Session.Update method is called I get the following error</p>
  
  <pre><code>Duplicate entry '1-1' for key 'PRIMARY'Could not execute command: INSERT INTO Selection (PlayerId, Number) VALUES (?p0, ?p1)
  </code></pre>
  
  <p>Which is self explanatory, but fixing it is not. Why is it trying to re-add the numbers, shouldn't it just delete the one I removed?</p>
  
  <p><strong>Update</strong></p>
  
  <p>I change the mapping from a Bag to a Set and now I don't get the duplicate key error. However it does not delete the number I removed from the list.</p>