I am modelling an e-learning system whereby a user can enroll on a course. A course can be made up of a series of content or a series of course sections which in turn contain content.
I have the models defined as follows:
public class Course
{
[Key]
public int CourseID { get; set; }
//1 to many relationship
public virtual ICollection<Content> Contents { get; set; }
public virtual ICollection<CourseSection> CourseSections { get; set; }
//many to many relationship
public virtual ICollection<User> Users { get; set; }
}
public class CourseSection
{
[Key]
public int CourseSectionID { get; set; }
public int CourseID { get; set; }
public virtual ICollection<Content> Contents { get; set; }
}
public class Content
{
[Key]
public int ContentID { get; set; }
//many-to-many mappings
public virtual ICollection<Course> Courses { get; set; }
public virtual ICollection<CourseSection> CourseSections { get; set; }
}
After initializing my context I can see that there are two tables created in the database that do not relate to the models that I have created. The following two tables are created unexpectedly and I would like to understand why:
ContentCourse: Content_ContentID, Course_CourseID
CourseSectionContent: CourseSection_CourseSectionID, Content_ContentID
Once I noticed that these two tables were being created I decided to create mapping tables for CourseContent and SectionContent by adding the following two models:
public class CourseContent
{
[Key, Column(Order = 0)]
public int CourseID { get; set; }
[Key, Column(Order = 1)]
public int ContentID { get; set; }
}
public class SectionContent
{
[Key, Column(Order = 0)]
public int CourseSectionID { get; set; }
[Key, Column(Order = 1)]
public int ContentID { get; set; }
}
Unfortunately these tables are still being created. Can anyone tell from my code where I am going wrong? Any help would be greatly appreciated.