title: how to insert data in database using database first approach and many to many relationship
body: <p>I am having 2 table studentmaster and subject they have many 2 many relationship :-</p>
  
  <p>My table structure is :-</p>
  
  <p><img src="https://i.stack.imgur.com/CBGN8.png" alt="enter image description here"></p>
  
  <p>How can i insert data in these table from mvc controller</p>
  
  <p>This is studentmaster.cs</p>
  
  <pre><code>public partial class studentmaster
      {
          public studentmaster()
          {
              this.subjects = new HashSet&lt;subject&gt;();
          }
  
      public int studentid { get; set; }
      public string studentname { get; set; }
      public Nullable&lt;System.DateTime&gt; dob { get; set; }
      public Nullable&lt;int&gt; registrationnumber { get; set; }
  
      public virtual ICollection&lt;subject&gt; subjects { get; set; }
  }
  </code></pre>
  
  <p>This is subject.cs</p>
  
  <p>using System;
      using System.Collections.Generic;</p>
  
  <pre><code>public partial class subject
  {
      public subject()
      {
          this.studentmasters = new HashSet&lt;studentmaster&gt;();
      }
  
      public int subjectid { get; set; }
      public string subjectname { get; set; }
  
      public virtual ICollection&lt;studentmaster&gt; studentmasters { get; set; }
  }
  </code></pre>
  
  <p>This Model3.context.cs</p>
  
  <pre><code>using System;
  using System.Data.Entity;
  using System.Data.Entity.Infrastructure;
  
  public partial class studentEntities : DbContext
  {
      public studentEntities() : base("name=studentEntities")
      {
      }
  
      protected override void OnModelCreating(DbModelBuilder modelBuilder)
      {
          throw new UnintentionalCodeFirstException();
      }
  
      public DbSet&lt;studentmaster&gt; studentmasters { get; set; }
      public DbSet&lt;subject&gt; subjects { get; set; }
      public DbSet&lt;sysdiagram&gt; sysdiagrams { get; set; }
  }
  </code></pre>