我们已经在code-first 约定一文中,已经知道了Code-First为每一个具体的类,创建数据表。

但是你可以自己利用继承设计领域类,面向对象的技术包含“has a”和“is a”的关系即,有什么,是什么,的关系,但是基于SQL关系的实体和数据表集合之前,只是有“has a ”的关系。数据库管理系统(SQL database management systems)不支持继承类型,所以,你怎么将面向对象的领域实体和关系型的数据库映射在一起呢???

下面有三种方式,在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.

这种方式,推荐一个表作为整个类的继承层次结构。这个表包含监听列可以和继承类之间很好的区分开来。这个是EF中默认的继承策略。

  • 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:

  1. Inheritance with EF Code First: Table per Hierarchy (TPH)
  2. Inheritance with EF Code First: Table per Type (TPT)
  3. 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.

在之前的环节中,我们已经看到了Code-First默认约定,下面一节,让我们来学一下怎么来配置我们的领域类,为了能够打破默认约定。

PS:这个继承的部分,我后面会深入看下里面的技术,然后翻译出来。请大家多多支持!!!

附上目录:

5.Inheritance Strategy(继承策略)【EFcode-first系列】的更多相关文章

  1. 7.翻译系列:EF 6中的继承策略(EF 6 Code-First 系列)

    原文地址:http://www.entityframeworktutorial.net/code-first/inheritance-strategy-in-code-first.aspx EF 6 ...

  2. Hibernate实体对象继承策略

    Hibernate继承策略总共同拥有三种,一种是共用一张表:一种是每一个类一张表,表里面储存子类的信息和父类的信息:另一种是通过表连接的方式.每一个类都有一张表,可是子类相应的表仅仅保存自己的信息,父 ...

  3. EF Code-First 学习之旅 继承策略

    Code First中有三种不同的方法表示继承层次关系 1.Table per Hierarchy (TPH): 这种方法建议用一个表来表示整个类的继承层次关系,表中包含一个识别列来区分继承类,在En ...

  4. JavaPersistenceWithHibernate第二版笔记-第六章-Mapping inheritance-003Table per concrete class with unions(@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)、<union-subclass>)

    一.代码 1. package org.jpwh.model.inheritance.tableperclass; import org.jpwh.model.Constants; import ja ...

  5. 设计模式之——浅谈strategy模式(策略模式)

    strategy模式,即策略模式.个人觉得吧,策略模式更多的是一种思维方式. 首先我们要知道,为什么需要策略模式.举个例子,比如用程序输出今天下午去玩什么. PlayGame 玩游戏 package ...

  6. JavaPersistenceWithHibernate第二版笔记-第六章-Mapping inheritance-005Table per subclass with joins(@Inheritance(strategy = InheritanceType.JOINED)、@PrimaryKeyJoinColumn、)

    一.结构 The fourth option is to represent inheritance relationships as SQL foreign key associations. Ev ...

  7. Entity Framework Code-First(7):Inheritance Strategy

    Inheritance Strategy in Code-First: We have seen in the Code First Conventions section that it creat ...

  8. EF CodeFirst系列(3)---EF中的继承策略(暂存)

    我们初始化数据库一节已经知道:EF为每一个具体的类生成了数据库的表.现在有了一个问题:我们在设计领域类时经常用到继承,这能让我们的代码更简洁且容易管理,在面向对象中有“has  a”和“is a”关系 ...

  9. Strategy(策略)模式

    1.概述 在软件开发中也常常遇到类似的情况,实现某一个功能有多种算法或者策略,我们可以根据环境或者条件的不同选择不同的算法或者策略来完成该功能.如查找.排序等,一种常用的方法是硬编码(Hard Cod ...

随机推荐

  1. 登陆数据库,界面一直保持正在登陆的状态,oracle使用界面无法登陆

    原因:关机时没有关闭oracle窗口. 导致在登陆数据库的时候,使用oracle的这个界面登陆时,界面一直保持''正在登陆''的状态,一旦点击就会卡住,使界面变得无法响应. 然后使用sqlplus仍然 ...

  2. MySQL 数据库事务与复制

    好久没有写技术文章了,因为一直在思考 「后端分布式」这个系列到底怎么写才合适. 最近基本想清楚了,「后端分布式」包括「分布式存储」和 「分布式计算」两大类. 结合实际工作中碰到的问题,以寻找答案的方式 ...

  3. ABP框架理论学习之Hangfire集成

    返回总目录 Hangfire是一个综合的后台工作管理者.你可以将Hangfire集成到ABP中,这样就可以不使用默认的后台工作管理者了.但你仍然可以为Hangfire使用相同的后台工作API.这样,你 ...

  4. 玩转JavaScript OOP[3]——彻底理解继承和原型链

    概述 上一篇我们介绍了通过构造函数和原型可以实现JavaScript中的“类”,由于构造函数和函数的原型都是对象,所以JavaScript的“类”本质上也是对象.这一篇我们将介绍JavaScript中 ...

  5. 同步博客到CSDN

    经过一些朋友的多次邀请,现同步博客到CSDN,地址:http://blog.csdn.net/knightswarrior.

  6. KnockoutJS 3.X API 第八章 映射(mapping)插件

    Knockout旨在允许您将任意JavaScript对象用作视图模型. 只要一些视图模型的属性是observables,您可以使用KO将它们绑定到您的UI,并且UI将在可观察属性更改时自动更新. 大多 ...

  7. ComboTree 的json格式和引用

    在easyui内,用 <select>实现combotree. <td ><select class="easyui-combotree" url=& ...

  8. thinkPHP入门

    什么是框架 框架就是一定结构的代码,框架提供一个开发web程序的基础架构以及常用的功能 代码,PHP框架的web程序开发拜倒了流水线上. php框架就是一定要按别人规定好的架构编写. php开发框架有 ...

  9. 设置Distribution clean up 每次删除Command的数量

    Replication Job “Distribution clean up: distribution” 默认设置是,每10minutes运行一次,每次删除2000个Command.这对于有1.9亿 ...

  10. Newtonsoft.json中 linq to json 和序列化哪个快?

    Newtonsoft.json是最常用的json序列化组件,当然他不是最快的,但是是功能最全的.. using System; using System.Collections.Generic; us ...