title: Fluent Nhibernate save child.parentid = parentId on new parent & Child
body: <p>I'm trying to save a new parent item &amp; new child item to a legacy database</p>
  
  <p>I get my data just fine, when I save it saves both the parent and the child.  however the Child's SillyNameParentId is always 0</p>
  
  <p>The table structure I can't change so I have to figure out how to make this work. </p>
  
  <p>Here is the SQL generated </p>
  
  <blockquote>
    <p>NHibernate: INSERT INTO SillyNameParent(Description, Active) VALUES
    (@p0, @p1); select     SCOPE_IDENTITY();@p0 = 'Test' [Type: String
    (1073741823)], @p1 = True [Type: Boolean (0)] NHibernate: INSERT INTO
    SillyChild (SillyNameCategoryId, sillyNameParentid) VALUES (@p0, @p1);
    select SCOPE_IDENTITY();@p0 = 0 [Type: Int32 (0)], @p1 = 1 [Type:
    Int32 (0)]</p>
  </blockquote>
  
  <p>Ultimately I want @p1 to be set as SillyNameParentId/Parentid</p>
  
  <p>Tables:</p>
  
  <pre><code>SillyNameParent
      Column PK-IsIdentity: ParentId
      Column varchar(255): Description
      Column bit: Active
  
  SillyChild //I'm a lookup table 
      Column int IsIdentity: Id
      Column int PK: SillyNameParentId
      Column int PK: SillyNameCategoryID
  </code></pre>
  
  <p>MODELS:</p>
  
  <pre><code>public class SillyNameParent: Entity
  {
      public SillyNameParent()
      {
          Children= new List&lt;SillyChild&gt;();
      }
      public virtual string AreaOfConcernDesc { get; set; }
      public virtual bool Active { get; set; }
      public virtual IList&lt;SillyChild&gt; Children{ get; set; }
  }
  
  public class SillyChild: Entity
  {
      public virtual int SillyNameParentId { get; set; }
      public virtual int SillyNameCategoryId{ get; set; }
      public virtual SillyNameParent Parent { get; set; }
  
  }
  </code></pre>
  
  <p>MAPS:</p>
  
  <pre><code>public class SillyNameParentMap : IAutoMappingOverride&lt;SillyNameParent&gt;
  {
      public void Override(AutoMapping&lt;SillyNameParent&gt; mapping)
      {
          mapping.Table("SillyNameParent");
          mapping.Id(x =&gt; x.Id).Column("ParentId").GeneratedBy.Identity();
          mapping.Map(x =&gt; x.Description).Not.Nullable();
          mapping.Map(x =&gt; x.Active).Nullable();
          mapping.HasMany(x =&gt; x.children)
              .Cascade.All()
              .KeyColumn("SillyNameParentId")
              .Not
              .LazyLoad();
      }
  }
  
  public class SillyChildMap: IAutoMappingOverride&lt;SillyChild&gt;
  {
      public void Override(AutoMapping&lt;SillyChild&gt; mapping)
      {
          mapping.Table("SillyChild");
          mapping.Id(x =&gt; x.Id).Column("Id").GeneratedBy.Identity();
          mapping.Map(x =&gt; x.SillyNameParentId).Not.Nullable();
          mapping.Map(x =&gt; x.SillyNameCategoryId).Not.Nullable();
          mapping.HasOne(x =&gt; x.Parent).ForeignKey("SillyNameParentId");
      }
  }
  </code></pre>