I have many-to-many relation Student-Course which I realised using virtual collection list and I got the next generated migration code :
CreateTable(
"dbo.PersonCourses",
c => new
{
Person_Id = c.Int(nullable: false),
Course_Id = c.Int(nullable: false),
})
.PrimaryKey(t => new { t.Person_Id, t.Course_Id })
.ForeignKey("dbo.People", t => t.Person_Id, cascadeDelete: true)
.ForeignKey("dbo.Courses", t => t.Course_Id, cascadeDelete: true)
.Index(t => t.Person_Id)
.Index(t => t.Course_Id);
Now I want to map table PersonCourses to some C# class and I wrote
[Table("PersonCourses")]
public class PersonCourses
{
[ForeignKey("Person")]
[Required]
public int PersonId { get; set; }
[ForeignKey("Course")]
[Required]
public int CourseId { get; set; }
}
but it fails with : "PersonCourses" has no key defined.Define the key for this EntityType.