title: Fluent NHibernate Child collection persistence issues
body: <p>I have the following mapping classes (only the relevant part copied):</p>
  
  <pre><code>public class CardTemplateMapping : ClassMap&lt;CardTemplate&gt;
  {
      public CardTemplateMapping()
      {
          Table("cardtemplate");
  
          Id(x =&gt; x.Id)
              .Column("id")
              .GeneratedBy.Native();
  
          HasMany(x =&gt; x.CostStructures)
              .KeyColumn("cardtemplate_id")
              .Cascade.All();
  
      }
  }
  public class CostStructureMapping : ClassMap&lt;CostStructure&gt;
  {
      public CostStructureMapping()
      {
          Table("coststructure");
  
          Id(x =&gt; x.Id)
              .Column("id")
              .GeneratedBy.Native();
  
          References(x =&gt; x.CardTemplate)
              .Column("cardtemplate_id");
  
          HasMany(x =&gt; x.CostComponents)
              .KeyColumn("coststructure_id")
              .Cascade.AllDeleteOrphan();
  
      }
  }
  public class CostStructureComponentMapping : ClassMap&lt;CostStructureComponent&gt;
  {
      public CostStructureComponentMapping()
      {
          Table("CostStructureComponent");
  
          Id(x =&gt; x.Id)
              .Column("id")
              .GeneratedBy.Native();
  
          References(x =&gt; x.CostStructure)
              .Column("coststructure_id");
  
          References(x =&gt; x.ResourceType)
              .Column("resourcetype_id");
      }
  }
  </code></pre>
  
  <p>Nhibernate loads the relations as I intended. But two parts of the Mapping seem a bit weird (either that or my expectations are weird).</p>
  
  <p>First:</p>
  
  <pre><code> CostStructure structure = new CostStructure() { CardTemplate = template };
   template.CostStructures.Add(structure);
   Session.Save(template);
   Session.Flush();
  </code></pre>
  
  <p>This does not save the new <code>CostStructure</code> instance. Why?</p>
  
  <p>Second one: Assuming I have loaded a <code>CardTemplate</code> having a <code>CostStructure</code> containing three <code>CostStructureComponent</code> entities. Now I want to remove one of those <code>CostStructureComponents</code> from the <code>CostStructure</code>.<br>
  I tried the following : </p>
  
  <pre><code>costStructure.CostComponents.Remove(component);
  component.CostStructure = null;
  session.Save(template)
  </code></pre>
  
  <p>Now, I know that explicitly deleting explicitly works, but shouldn't the <code>DeleteOrphan</code> part also assert that the component, now without <code>CostStructure</code> to reference, is deleted? Instead, NHibernate tries to perform the following update: </p>
  
  <pre><code>UPDATE CostStructureComponent 
  SET amount = @p0, 
       coststructure_id = @p1, 
       resourcetype_id = @p2
  WHERE id = @p3;
  
  @p0 = 1 [Type: Int32 (0)], 
  @p1 = NULL [Type: Int64 (0)], 
  @p2 = 5 [Type: Int64 (0)], 
  @p3 = 13 [Type: Int64 (0)]
  </code></pre>
  
  <p>Could it be Equals / GetHashCode have been implemented the wrong way?</p>
  
  <p>Sorry, it's late, been a long day and so forth...If I'm talking gibberish, please let me know...</p>