title: NHibernate not loading child objects
body: <p>I have following class and associated mappings (Fluent NHibernate):</p>
  
  <pre><code>public class Category
  {
      public virtual int Id { get; set; }
      public virtual string Name { get; set; }
      public virtual string Description { get; set; }
      public virtual Category ParentCategory { get; set; }
      public virtual IList&lt;Category&gt; ChildCategories { get; set; }
  }
  </code></pre>
  
  <p>Mappings:</p>
  
  <pre><code>public class CategoryMap : ClassMap&lt;Category&gt;
  {
      public CategoryMap()
      {
          Table("Categories");
  
          Id(x =&gt; x.Id).Column("Id").CustomType("Int32").Access.Property()
           .CustomSqlType("int").Not.Nullable().Precision(10)
           .GeneratedBy.Identity();
  
          Map(x =&gt; x.Description).Column("Description").Nullable()
           .Generated.Never().CustomType(typeof (string)).Access
           .Property().Length(250);
  
          Map(x =&gt; x.Name).Not.Nullable().Generated.Never().CustomType("string")
           .Access.Property().Column("Name").Length(50);
  
          References(x =&gt; x.ParentCategory).Column("ParentCategoryId");
          HasMany(x =&gt; x.ChildCategories).KeyColumn("ParentCategoryId").Inverse()
           .AsBag().Fetch.Select();
      }
  }
  </code></pre>
  
  <p>I creating two <code>Category</code> object as follows:</p>
  
  <pre><code>var c = new Category
          {
              Name = "Ebooks",
              Description = "Contains awz, mobi, pdf, epub and other 
                  electronic books"
          };
  var cc = new Category
           {
              Name = "Kindle Books",
              Description = "Contains Kindle ebook reader format books 
                      (awz, mobi)",
              ParentCategory = c
           };
  session.SaveOrUpdate(c);
  session.SaveOrUpdate(cc);
  </code></pre>
  
  <p>When I try to access saved objects:</p>
  
  <pre><code>var c = session.Load&lt;Category&gt;(1);
  var cc = c.ChildCategories;
  </code></pre>
  
  <p><code>c</code> contains the <code>Category</code> object with <code>Id</code> of 1 but its <code>ChildCategories</code> property is <code>null</code>.</p>
  
  <p>What I am doing wrong?</p>
  
  <p>PS:- This is my first experiment with <code>NHibernate</code> and so with <code>Fluent NHibernate</code>.</p>
  
  <p><strong>EDIT:-</strong> The following stuff worked. I needed to close the session before opening it again for reading. Otherwise it read just from memory nad as @Holf has pointed out I needed to add <code>Child Category</code> to <code>Category</code> like:</p>
  
  <p>c.ChilCategories.Add(cc);</p>
  
  <p>I just did as follows:</p>
  
  <pre><code>var session = sf.OpenSession();
  CreateCategory(session);//ADDED TWO CATEGORIES EBooks, Kindle Ebooks
  session.Close();
  
  session = sf.OpenSession();
  FetchCategories(session);//READ CATEGORY EBooks AND ASSOCIATED CHILDREN
  session.Close();
  </code></pre>