假设我有以下实体:
public class Person { ... }
public class Student : Person { ... }
public class Teacher : Person { ... }
在上下文类中,以下哪个更好(以及为什么?)
DbSet<Person> Persons { get; set; }
并使用context.Persons.OfType<Student>()
或DbSet
s(DbSet<Person>
,DbSet<Student>
和DbSet<Teacher>
)或DbSet
和DbSet<Student>
)创建2 DbSet<Teacher>
个谢谢!
答案 0 :(得分:0)
仅创建DbSet<Person> Persons { get; set; }
并按如下方式修饰继承类
[Table("Students")]
public class Student : Person { ... }
[Table("Teachers")]
public class Teacher : Person { ... }