title: Why does my class save one collection to the database and not the other?
body: <p>This is driving me crazy. I can get one of the collections to save on a class, but not the other.</p>
  
  <p>I have a class called <code>Category</code></p>
  
  <pre><code>public Category()
  {
      Items = new List&lt;Item&gt;();
      Prices = new List&lt;Price&gt;();
  }
  </code></pre>
  
  <p>That has these two methods that are pretty much identical. The constructors set a property called <code>Category</code> and their <code>Name</code> and <code>Price</code> respectively.</p>
  
  <pre><code>public virtual Item AddItem(string name)
  {
      var item = new Item(this, name);
      Items.Add(item);
      return item;
  }
  
  public virtual Price AddPrice(decimal price)
  {
      var price = new Price(this, price);
      Prices.Add(price);
      return price;
  }
  </code></pre>
  
  <p>Mappings</p>
  
  <pre><code>public class CategoryMap : ClassMap&lt;Category&gt;
  {
      public CategoryMap()
      {
         // Other properties
  
         HasMany(x=&gt;x.Items).Cascade.AllDeleteOrphan();
         HasMany(x=&gt;x.Prices).Cascade.AllDeleteOrphan();
      }
  }
  </code></pre>
  
  <p>As you can see, the two collections are mapped the exact same way.</p>
  
  <p>The maps for <code>Price</code> and <code>Item</code> both have the same mapping</p>
  
  <pre><code>References(x=&gt;x.Category);
  </code></pre>
  
  <p>As far as I can tell, almost everything about these two are identical. Here's the problem</p>
  
  <pre><code>category.AddItem(someName);
  session.Save(category);    // Works
  
  category.AddPrice(somePrice);
  session.Save(category);    // Doesn't work
  </code></pre>
  
  <p>These are in a file I use to populate a test database. Saving the Item works fine. Saving the Price does not. The classes and the mappings are identical. I can't figure it out.</p>
  
  <p>The mappings should work fine as calling the constructor directly works fine</p>
  
  <pre><code>session.Save(new Price(category, 1));
  </code></pre>
  
  <p>So why does Category save one collection and not the other? I ran profiler, and the class isn't even trying to save the Price collection.</p>
  
  <p>Update:</p>
  
  <p>As Gabe points out in the comment, if I swap the calls so that Price is called before Item, the Price goes into the database and Item does not.</p>
  
  <p>If I call <code>session.Flush()</code> after every collection update, it works fine. Am I supposed to have to do this, or is there a way to fix my mapping so that it works?</p>