c# - Entity Framework DB First - 模型中的继承问题

标签 c# mysql wpf entity-framework db-first

我在使用 EF DB First 时遇到一些问题。假设我有:

  • 一 table 人
  • 表 Student,其外键指向 Person
  • 表 Teacher 的外键指向 Person

DB structure

从数据库创建的模型生成以下类:

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) 映射。尝试这里的解决方案:

Entity Framework DB-First, implement inheritance

关于c# - Entity Framework DB First - 模型中的继承问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32521415/

相关文章:

mysql - 将日期/时间添加到 MySQL 表?

c# - 如何在用户控件中使用继承的属性?

wpf - VisualStateManager同时出现在WPF Toolkit和PresentationFramework中 - 如何解决

c# - 如何从 RTF 文件中获取文本大小和颜色?

c# - 在 C# 中使用 linq 更新 xml

c# - log4net 如何在页脚后添加新行

mysql - 通过时间戳进行 SQL 分组产生了意想不到的结果

c# - NUnit3 : Assert. 抛出异步任务

mysql - mysql大表如何正确使用索引?

c# - 使用 WPF 捕获视频的第一帧