Entity Framework Code-First(7):Inheritance Strategy
2016-07-05 16:19
381 查看
Inheritance Strategy in Code-First:
We have seen in the Code First Conventions section that it creates database tables for each concrete domain class. However, You can design your domain classes using inheritance. Object-oriented techniques include "has a" and "is a" relationship, whereas SQL-based relational model has only a "has a" relationship between tables. SQL database management systems don't support type inheritance. So, how would you map object-oriented domain classes with the relational database?Below are three different approaches to represent an inheritance hierarchy in Code-First:
Table per Hierarchy (TPH): This approach suggests one table for the entire class inheritance hierarchy. Table includes discriminator column which distinguishes between inheritance classes. This is a default inheritance mapping strategy in Entity Framework.
Table per Type (TPT): This approach suggests a separate table for each domain class.
Table per Concrete class (TPC): This approach suggests one table for one concrete class, but not for the abstract class. So, if you inherit the abstract class in multiple concrete classes, then the properties of the abstract class will be part of each table of the concrete class.
We are not going into detail here. Visit the following reference link for more detailed information:
Inheritance with EF Code First: Table per Hierarchy (TPH)
Inheritance with EF Code First: Table per Type (TPT)
Inheritance with EF Code First: Table per Concrete class (TPC)
We have seen default Code First conventions in the previous section. Learn how to configure domain classes in order to override these conventions in the next section.
相关文章推荐
- Java多线程基础-2-简单继承Thread,实现Runnable例子
- hadoop的hdfs命令
- C#解决SQlite并发异常问题的方法(使用读写锁)
- 一致性哈希算法(consistent hashing) .
- WebViewJavaScriptBridge源码解析(一)
- android ViewFlipper 详细用法,附源代码+图片资源
- 响应式网页设计:web产品RWD概念
- 如何修改Windows的默认安装路径
- linux debian 时间设置中无法选择“自动设定时间和日期”
- Entity Framework Code-First(6):Database Initialization
- 刘姝威:超图软件如何实现利润爆发式增长
- Mysql体系构架详解——内存
- Jmockit使用指南
- 关于Linux的一些常用命令
- Java内部类小结
- shiro角色配置
- 华为机试---查找兄弟单词
- "给我评分" 模块,跳转到相应的应用商店--apk展示详情页面
- .net 生成二维码水印
- mysql - Navicat中无法编辑查询结果数据