大家好我想弄清楚如何做以下事情。我有很多实体会使用以下模式,我不确定刺穿它的最佳方式。
我将使用虚拟类来演示我想要完成的任务。
首先,我们首先采用一种名为IClass
public interface IClass
{
string Title { get; set; }
int Id { get; set; }
ICollection<IPerson> People{get;set;}
}
public class StudentClass:IClass
{
public string Title { get; set; }
public int Id { get; set; }
public ICollection<IPerson> People { get; set; }
}
public class TeacherClass : IClass
{
public string Title { get; set; }
public int Id { get; set; }
public ICollection<IPerson> People { get; set; }
}
public class Employee : IPerson
{
public string FirstName { get; set; }
public int Id { get; set; }
public int EmployeeNumber { get; set; }
public string LastName { get; set; }
}
public class Student : IPerson
{
public string FirstName { get; set; }
public int Id { get; set; }
public string LastName { get; set; }
public virtual ICollection<Course> Courses { get; set; }
}
我想要做的是使用modelBuilder
注册该类特定的ICollection<IPerson>
。例如,TeacherClass
IPerson
应该是Employee
和StudentClass
,它应该是Student
我该如何做到这一点?