我有问题,因为当我将以下内容添加到班级时,Course
我只有 2 个表而不是 3 个
public int PersonId { get; set; }
[ForeignKey("PersonId")]
public virtual Person Student { get; set; }
你没有这三行都很好,但我需要一个额外的领域在课堂课程
public class Person
{
public int PersonId { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public virtual ICollection<Course> CoursesAttending { get; set; }
}
public class Course
{
public int CourseId { get; set; }
public string Title { get; set; }
public int PersonId { get; set; }
[ForeignKey("PersonId")]
public virtual Person Student { get; set; }
public virtual ICollection<Person> Students { get; set; }
}
public class SchoolContext : DbContext
{
public DbSet<Course> Courses { get; set; }
public DbSet<Person> People { get; set; }
}
class Program
{
static void Main(string[] args)
{
Database.SetInitializer<SchoolContext>(
new DropCreateDatabaseAlways<SchoolContext>());
SchoolContext db = new SchoolContext();
var cos = from d in db.Courses
select d;
}
}
请帮我