title: Insert to parent and child tables
body: <p>Hi 
  I have parent and child table like below</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  
                      ------- parent --------------
  &lt;hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"&gt;
    &lt;class name="HibernateSample.StudMarks,HibernateSample" table="StudMarks" lazy="false"&gt;
      &lt;id name="Sno" column="SNO" type="int"&gt;
        &lt;generator class="assigned"/&gt;
      &lt;/id&gt;
      &lt;many-to-one name="Student" column="ID" not-null="true"/&gt;
      &lt;property name="Marks" column="Marks" type="int" not-null="true" /&gt;
      &lt;property name="Rank" column="Rank" type="int" not-null="true" /&gt;
    &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  
                 ------- child --------------
  &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"&gt;
    &lt;class name="HibernateSample.Student,HibernateSample" table="Student" lazy="false"&gt;
      &lt;id name="Id" column="ID" type="int"&gt;
        &lt;generator class="native" /&gt;
      &lt;/id&gt;
      &lt;property name="Name" column="Name" type="string" not-null="true" /&gt;
      &lt;property name="Standard" column="Standard" type="string" not-null="true" /&gt;
      &lt;bag name="StudMarks" cascade="all" lazy="false"&gt;
        &lt;key column="ID" not-null="true"/&gt;
        &lt;one-to-many class="HibernateSample.StudMarks,HibernateSample" /&gt;
      &lt;/bag&gt;
    &lt;/class&gt;
  &lt;/hibernate-mapping&gt;
  </code></pre>
  
  <p>and in .cs file i have like written code like below to insert into parent and child.</p>
  
  <pre><code>        StudMarks sm = new StudMarks(); 
          Student st = new Student();
          List&lt;StudMarks&gt; sms = new List&lt;StudMarks&gt;();
          st.Id = 9;
          st.Name = "stud 999";
          st.Standard = "99";
          sm.Sno = 9;
          sm.Marks = 99;
          sm.Rank = 9;            
  
          sm.Student = st;              ------ **Line 1**
          st.StudMarks = sms;           ------ **Line 2**
  
          session.Save(sm);            
          session.Flush();
  </code></pre>
  
  <p>If i commENT "Line 1" in above code only child is inserting. If i comment "Line 2" foreign key constraint error is throwing.</p>
  
  <p><strong>Tables:</strong></p>
  
  <pre><code>CREATE TABLE [dbo].[Student](
  [ID] [int] IDENTITY(1,1) NOT NULL, -- PRIMARY KEY
  [Name] [varchar](50) NOT NULL,
  [Standard] [varchar](50) NOT NULL,
  
  CREATE TABLE [dbo].[StudMarks](
  [SNO] [int] NOT NULL, -- PRIMARY KEY
  [ID] [int] NOT NULL, -- FOREIGN KEY
  [Marks] [int] NOT NULL,
  [Rank] [int] NOT NULL,)
  </code></pre>
  
  <p>Please let me know how to insert in parent and child at a time in single save operation.</p>