You need to declare Courses_Students class
public class Courses_Students { [Key] public int CourseId { get; set; } public int StudentId { get; set; } public int DummyColumn { get; set; } public virtual ICollection<Course> Courses { get; set; } public virtual ICollection<Student> Students { get; set; } }
The key on CourseId is to prevent a compilation error, then you will override it.
Then, in your DbContext class, you override OnModelCreating as follows:
protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity<Courses_Students>() .HasKey(e => new { e.CourseId, e.StudentId }) .MapSingleType() .ToTable("Courses_Students"); }
Christian lavallee
source share