title: Insert data to multiple tables in single query
body: <p>currently I am learning ASP.NET and I stuck on storing data to multiple tables. Database model is shown bellow:</p>
  
  <p><img src="https://i.stack.imgur.com/xrwmy.png" alt="Database model"></p>
  
  <p>What I want to achieve is when I add new contact to Contact table to get last insert ID and automatically insert data for tables Phone/Tag/Email (if there is some data for that tables). Is there a chance to do it in single query or do I need to run fresh query for each table?</p>
  
  <p>Here is model that is used in Controller:</p>
  
  <pre class="lang-cs prettyprint-override"><code> public partial class Contact
      {
          public Contact()
          {
              this.Emails1 = new HashSet&lt;Email&gt;();
              this.Phones1 = new HashSet&lt;Phone&gt;();
              this.Tags1 = new HashSet&lt;Tag&gt;();
          }
  
          public int id { get; set; }
          public string firstname { get; set; }
          public string lastname { get; set; }
          public string address { get; set; }
          public string city { get; set; }
          public Nullable&lt;byte&gt; bookmarked { get; set; }
          public string notes { get; set; }
  
          public virtual ICollection&lt;Email&gt; Emails1 { get; set; }
          public virtual ICollection&lt;Phone&gt; Phones1 { get; set; }
          public virtual ICollection&lt;Tag&gt; Tags1 { get; set; }
      }
  }
  </code></pre>
  
  <p>Here is model For Phone/Tags/Email tabels (it's same with different name in one column)</p>
  
  <pre class="lang-cs prettyprint-override"><code>public partial class Email
      {
          public int id { get; set; }
          public int id_contact { get; set; }
          public string email1 { get; set; }
  
          public virtual Contact Contact1 { get; set; }
      }
  </code></pre>
  
  <p>Here is controller class that ads new row to database:</p>
  
  <pre class="lang-cs prettyprint-override"><code> public string AddContact(Contact contact)
          {
              if (contact != null)
              {
  
                  db.Contacts.Add(contact);
                  db.SaveChanges();
                      return "Contact Added";
              }
              else
              {
                  return "Invalid Record";
              }
          }
  </code></pre>