When setting up a many-to-many relationship with Code First approach, by default the join table only includes 2 columns (FK to PK of the 2 tables).
1) Is it possible/How can I setup a join table that will include some additional fields, and 2) how do I fill these values via code?
For example:
class Student
{
public int Id { get; set; }
public string Name { get; set; }
public List<Course> Courses { get; set; }
}
class Course
{
public int Id { get; set; }
public string Name { get; set; }
public List<Student> Students { get; set; }
}
class MyDbContext : DbContext
{
public DbSet<Student> Students { get; set; }
public DbSet<Course> Courses { get; set; }
}
A simple db with Students and Courses with a many-to-many relationship. However for each join Student-Course, I also want a field, for example: PercentComplete, that tracks how far a student is in each course.
How can this be achieved?
Thanks