我在使用 EF DB First 时遇到一些问题。假设我有:
- 一 table 人
- 表 Student,其外键指向 Person
- 表 Teacher 的外键指向 Person
从数据库创建的模型生成以下类:
public class Person{
this.Student= new HashSet<Student>();
this.Teacher= new HashSet<Teacher>();
}
public class Student{}
public class Teacher{}
我真正想看到的是
public class Person{}
public class Student:Person{}
public class Teacher:Person{}
是否有任何配置约定或我缺少的任何内容来获取继承的类?
更新
类以这种方式生成,因为模型指定了 Person、Teacher 和 Student 之间的这些关联。那么我的问题应该是...有什么方法可以使用 EF 从数据库创建模型,以便该模型包含从其他模型继承的类吗?
最佳答案
您正在寻找按类型表 (TPT) 映射。尝试这里的解决方案:
关于c# - Entity Framework DB First - 模型中的继承问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32521415/