title: Adding column in Entity Framework 6.1 - Many-To-Many - Code First
body: <p>Just as an example I'm using the code from this article on codeproject: <a href="http://www.codeproject.com/Articles/234606/Creating-a-Many-To-Many-Mapping-Using-Code-First" rel="noreferrer">http://www.codeproject.com/Articles/234606/Creating-a-Many-To-Many-Mapping-Using-Code-First</a></p>
  
  <p><img src="https://i.stack.imgur.com/9pkrh.png" alt="enter image description here"></p>
  
  <p>Im trying to do something similar in my code but I also want a quantity property, so:</p>
  
  <ol>
  <li>One course can have many persons</li>
  <li>One Person can have many courses</li>
  <li>Each person can choose a quantity of each course. (I know that it does not make sense to choose the same course twice but it's just an example, or replace courses with types of hamburgers :-) )</li>
  </ol>
  
  <p>I'm thinking I have to add a column in PersonCourses table named Quantity but I have no idea how to do that in Code First.</p>
  
  <p>The code:</p>
  
  <pre><code>public class Person
  {
    public int PersonId { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
  
    public ICollection&lt;Course&gt; CoursesAttending { get; set; }
  
    public Person()
    {
      CoursesAttending = new HashSet&lt;Course&gt;();
    }
  }
  
  public class Course
  {
    public int CourseId { get; set; }
    public string Title { get; set; }
  
    public ICollection&lt;Person&gt; Students { get; set; }
  
    public Course()
    {
      Students = new HashSet&lt;Person&gt;();
    }
  }
  
  public class SchoolContext : DbContext
  {
    public DbSet&lt;Course&gt; Courses { get; set; }
    public DbSet&lt;Person&gt; People { get; set; }
  
    public SchoolContext()
      : base("MyDb")
    {
    }
  }
  </code></pre>
  
  <p>Context:</p>
  
  <pre><code>public class SchoolContext : DbContext
  {
    public DbSet&lt;Course&gt; Courses { get; set; }
    public DbSet&lt;Person&gt; People { get; set; }
  
    public SchoolContext()
      : base("MyDb")
    {
    }
  
    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
      modelBuilder.Entity&lt;Course&gt;().
        HasMany(c =&gt; c.Students).
        WithMany(p =&gt; p.CoursesAttending).
        Map(
         m =&gt;
         {
           m.MapLeftKey("CourseId");
           m.MapRightKey("PersonId");
           m.ToTable("PersonCourses");
         });
    }
  }
  </code></pre>