title: How to Insert Row to Parent Table and another Table while in the Parent Table Create Form? - ASP MVC 5
body: <p>For example I have a table called 'Child' which is connected to another table (one-to-many relationship) to another table called 'Siblings'. What I want to do is that in the 'Child' Create Form I also have a sub-form with the field for 'Siblings' table (like 'name', 'age', etc.)</p>
  
  <p>The problem is the 'sibling' Table has a foreign key connected to 'child'. And, when the user clicks on Submit in 'child' Create Form (together with the sub-form for the 'sibling' Table) there will be an error because the 'child' row has not yet been created resulting to no foreign keys yet.</p>
  
  <p>Thus, is there a way to simultaneously make an Insert in 'child' and 'sibling' Table using one Create Form?</p>
  
  <p>Note: I am using the ADO.NET Entity Framework to create the Controllers and Views for both tables/models. I am also using MySQL for VS2015 Community.</p>
  
  <p>This is my 'child' Model:</p>
  
  <pre><code>public partial class child
  {
      [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
      public child()
      {
          this.siblings = new HashSet&lt;sibling&gt;();
      }
  
      public int child_id { get; set; }
      public string last_name { get; set; }
      public string first_name { get; set; }
      public string middle_name { get; set; }
      public string gender { get; set; }
      public Nullable&lt;int&gt; age { get; set; }
  
      [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
      public virtual ICollection&lt;sibling&gt; siblings { get; set; }
  }
  </code></pre>
  
  <p>This is my 'sibling' Model:</p>
  
  <pre><code> public partial class sibling
  {
      public int sibling_id { get; set; }
      public int child_id { get; set; }
      public Nullable&lt;int&gt; age { get; set; }
      public string gender { get; set; }
  
      public virtual child child { get; set; }
  }
  </code></pre>
  
  <p>Screenshot of the .EDMX:
  <a href="http://i.stack.imgur.com/AuM79.png" rel="nofollow">My .EDMX diagram screenshot</a></p>