title: FluentNhibernate Mapping Dictionaries Foreign Key Remains Null
body: <p>I have a simple Fluent-NHibernate mapping that gives me a headache! I'm trying to map a dictionary for one of the entities, but its FK remains null. </p>
  
  <p>Here's the entities code:</p>
  
  <pre><code>public class Person
  {
      public Person()
      {
          PhoneNumbers = new Dictionary&lt;string, Phone&gt;();
      }
  
      public virtual int Id { get; set; }
      public virtual string Name { get; set; }
      public virtual IDictionary&lt;string, Phone&gt; PhoneNumbers { get; set; }
  }
  
  public class Phone
  {
      public virtual int Id { get; set; }
      public virtual string Type { get; set; }
      public virtual string Number { get; set; }
  }
  </code></pre>
  
  <p>Now, Here's the mapping:</p>
  
  <pre><code>public class PersonClassMap : ClassMap&lt;Person&gt;
  {
      public PersonClassMap()
      {
          Id(x =&gt; x.Id).GeneratedBy.Identity();
          Map(x =&gt; x.Name);
          HasMany(x =&gt; x.PhoneNumbers).AsMap(y =&gt; y.Type).Cascade.All();
      }
  }
  
  public class PhoneClassMap : ClassMap&lt;Phone&gt;
  {
      public PhoneClassMap()
      {
          Id(x =&gt; x.Id).GeneratedBy.Identity();
          Map(x =&gt; x.Type);
          Map(x =&gt; x.Number);
      }
  }
  </code></pre>
  
  <p>Last, Here's the Test I'm doing: </p>
  
  <pre><code>    static void Main(string[] args)
      {
          ConfigureSessionFactory();
  
          using (var session = _sessionFactory.OpenSession())
          {
              var john = new Person();
              john.Name = "John";
  
              Phone home = new Phone
                               {
                                   Type = "Home",
                                   Number = "12345"
                               };
  
              john.PhoneNumbers.Add(home.Type, home);
  
              session.Save(john);
          }
      }
  </code></pre>
  
  <p>For some reason, when I look in the database, the phone record's <code>Person_id</code> remains null, and when I load the person back from the DB, the <code>PhoneNumbers</code> dictionary remains empty.</p>
  
  <p>Why? And how to solve this issue? What am I mapping wrong?</p>