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:

  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.

Entity Framework Code-First(7):Inheritance Strategy的更多相关文章

  1. Entity Framework Code first(转载)

    一.Entity Framework Code first(代码优先)使用过程 1.1Entity Framework 代码优先简介 不得不提Entity Framework Code First这个 ...

  2. Entity Framework Code First (三)Data Annotations

    Entity Framework Code First 利用一种被称为约定(Conventions)优于配置(Configuration)的编程模式允许你使用自己的 domain classes 来表 ...

  3. Entity Framework Code First (二)Custom Conventions

    ---------------------------------------------------------------------------------------------------- ...

  4. Entity Framework Code First (一)Conventions

    Entity Framework 简言之就是一个ORM(Object-Relational Mapper)框架. Code First 使得你能够通过C#的类来描述一个模型,模型如何被发现/检测就是通 ...

  5. Entity Framework Tutorial Basics(11):Code First

    Code First development with Entity Framework: Entity Framework supports three different development ...

  6. Entity Framework Code First (七)空间数据类型 Spatial Data Types

    声明:本文针对 EF5+, Visual Studio 2012+ 空间数据类型(Spatial Data Types)是在 EF5 中引入的,空间数据类型表现有两种: Geography (地理学上 ...

  7. Entity Framework Code First (四)Fluent API - 配置属性/类型

    上篇博文说过当我们定义的类不能遵循约定(Conventions)的时候,Code First 提供了两种方式来配置你的类:DataAnnotations 和 Fluent API, 本文将关注 Flu ...

  8. Entity Framework Code First (八)迁移 Migrations

    创建初始模型和数据库 在开始使用迁移(Migrations)之前,我们需要一个 Project 和一个 Code First Model, 对于本文将使用典型的 Blog 和 Post 模型 创建一个 ...

  9. Entity Framework Code First (六)存储过程

    声明:本文只针对 EF6+ 默认情况下,Code First 对实体进行插入.更新.删除操作是直接在表上进行的,从 EF6 开始你可以选择使用存储过程(Stored Procedures) 简单实体映 ...

  10. Entity Framework Code First (五)Fluent API - 配置关系

    上一篇文章我们讲解了如何用 Fluent API 来配置/映射属性和类型,本文将把重点放在其是如何配置关系的. 文中所使用代码如下 public class Student { public int ...

随机推荐

  1. 本地储存(localStorage)记录

    - 本地存储 + localStorage.getItem("search_history") 获取本地存储 + localStorage.setItem("a" ...

  2. Spring Cloud之网关搭建

    统一由网关进行拦截判断 要不放到每个服务里面就很不合适了 冗余 主要的: <dependency> <groupId>org.springframework.cloud< ...

  3. 中美贸易战再次开启,世界两极化进程正在加快形成!..... Copyright: 1688澳洲新闻网 Read more at: https://www.1688.com.au/world/international/2018/06/17/369368/

    中美贸易战再次开启,世界两极化进程正在加快形成! https://www.1688.com.au/world/international/2018/06/17/369368/

  4. snowflake(canvas)

    <!DOCTYPE html><html><head><meta http-equiv="Content-Type" charset=&q ...

  5. scanf和cin的返回值

    需要连续从标准输入读取数据时,可以采用下面两种不同的方式判断文件结束: [cpp] view plaincopy   int i; while(scanf("%d",&i) ...

  6. POJ1060 Modular multiplication of polynomials解题报告 (2011-12-09 20:27:53)

    Modular multiplication of polynomials Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3 ...

  7. java事务(一)——事务特性

    事务 什么是事务?事务通俗的讲就是要做的事,在计算机术语中一般指访问或更新数据库中数据的一个工作单元.说起事务,那么就要提到事务的ACID特性,即原子性(atomicity).一致性(consiste ...

  8. QToolBox

    QToolBox类似与以前qq好友分组的那种控件.每个分组是一个Item. 一.添加分组: 其中每个分组是通过一下函数添加的: int addItem(QWidget * w, const QIcon ...

  9. Debian for ARM install python 3.5.x

    /********************************************************************************** * Debian for ARM ...

  10. Agc003_E Sequential operations on Sequence

    传送门 题目大意 $1,2...n,n$个数从小到大排列,有$m$此操作,每次操作给定一个参数$x$,将当且数列作为循环节无限地展开下去,再取前$x$个作为新的数列,求最终的数列每个数出现的次数. $ ...