0

我已經在entityframework中使用代碼優先方法創建了一個應用程序。問題在多對多關係實體框架代碼第一種方法

在應用程序中,有兩個實體之間具有多對多的關係。

public class Course 
    { 

     [Key] 
     public int CourseId { get; set; } 
     public string Name { get; set; } 

     public ICollection<Student> Student{ get; set; } 
    } 


    public class Student 
    { 

     [Key] 
     public int StudentId { get; set; } 
     public string Name { get; set; } 

     public ICollection<Course> Course{ get; set; } 
    } 

當我執行該項目時,它創建學生表,課程表,StudentCourse表。

現在問題是,在StudentCourse表中只有兩個鍵,StudentID和CourseId 我想在該表中添加額外的列如何做到這一點?

+0

需要明確的是:您希望使用與有關的關係帶來額外的信息欄的連接表一個多一對多的關係? – chrylis

回答

0

聲明定義該表類:

public class Course 
{ 

    [Key] 
    public int CourseId { get; set; } 
    public string Name { get; set; } 

    public ICollection<Student> Student{ get; set; } 
} 

public class Student 
{ 

    [Key] 
    public int StudentId { get; set; } 
    public string Name { get; set; } 

    public ICollection<Course> Course{ get; set; } 
} 

public class StudentCourse 
{ 

    public int StudentId { get; set; } 
    public int CourseId { get; set; } 

    //More columns here 
}