我有两个表,人和课程这是表人:
public int ID { get; set; }
public int Name { get; set; }
public int CourseID1 { get; set; }
public int CourseID2 { get; set; }
对于课程:
public int CourseID { get; set; }
public int Name { get; set; }
每个人都有2门课程。我知道如何在asp.core代码中首先为它们建立关系
你的要求
每个人都有2门课程
所以我会像这样设计你的实体。人员课程将有ICollection课程。 ICollection意味着您至少有一个或多个与课程类别的关系数据(平均1人可以有超过1个课程)
人类
public int ID { get; set; }
public int Name { get; set; }
public ICollection<Courses> Courses { get; set; }
而Courses类必须引用回Person类。 1门课程属于一个人
public int CourseID { get; set; }
public string Name { get; set; }
public Person Person { get;set; }
如果您需要任何帮助,请告诉我
public int ID { get; set; }
public int Name { get; set; }
public int Course1CourseID { get; set; }
public Course Course1 { get; set; }
public int Course2CourseID { get; set; }
public Course Course2 { get; set; }
编辑:他这样问“人有2道菜”
id name Course1 Course2 1 john php asp 2 mike c#core
上面的模型会给你。