title: ASP.NET MVC using more than 1 DataContext Insert Method
body: <p>So i recently want to try using more than 1 database</p>
  
  <p>my main problem is the attribute on 1st and 2nd entities is different, so for example in 1st entities sample_table1 contain: "member_id" and "member_code" and the 2nd entities sample_table_2 contain "student_id" and "student_code" it's just the naming, the value of the attribute is same, so member_id = student_id, member_code = student_code</p>
  
  <p>Example:</p>
  
  <p>Controller</p>
  
  <pre><code>private MyEntities db = new MyEntities ();
  
  //not sure know by add this one, my controller can connect 2 database, but the intellisense is working when i'm using db2 class
  private MyEntities2 db2 = new MyEntities2 ();
  
  [HttpPost]
  [ValidateAntiForgeryToken]
  public ActionResult CreateSomething(sample_table1 sample_table1, sample_table2 sample_table2)
  {
     if (ModelState.IsValid)
     {
         //insert data to 1st Entities
         db.sample_table1.Add(sample_table1);
         db.SaveChanges();
  
         //insert data to 2nd Entities
         "???" // because the attribute name on 2nd entities is not the same as the 1st entities, i cannot using either sample_table1 &amp; sample_table2
         db2.SaveChanges();
  
     }
  }
  </code></pre>
  
  <p>Views</p>
  
  <pre><code>@model 1st_entites_data_model.Models.sample_table1
  // i don't know for sure but the 2nd entities data model won't appear when i add view    
  
  @{
      ViewBag.Title = "Create Something";
  }
  
  @using (Html.BeginForm("CreateSomething", "test", FormMethod.Post, new { enctype = "multipart/form-data" }))
  {
      @Html.AntiForgeryToken()
      @Html.ValidationSummary(true)
  
      //i'm using only the 1st entities, because there is no need for user input the same data value twice
      @Html.TextBoxFor(model =&gt; model.sample_table1.member_id)
      @Html.ValidationMessageFor(model =&gt; model.sample_table1.member_id)
  
      @Html.TextBoxFor(model =&gt; model.sample_table1.member_code)
      @Html.ValidationMessageFor(model =&gt; model.sample_table1.member_code)
  
  }
  </code></pre>
  
  <p>i cannot change the 2nd entities name because somebody else is making the 2nd entities, and i cannot edit the database structure...</p>
  
  <p>Thank You Very Much... </p>