Entity Framework Code-First(7):Inheritance Strategy
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.
Entity Framework Code-First(7):Inheritance Strategy的更多相关文章
- Entity Framework Code first(转载)
一.Entity Framework Code first(代码优先)使用过程 1.1Entity Framework 代码优先简介 不得不提Entity Framework Code First这个 ...
- Entity Framework Code First (三)Data Annotations
Entity Framework Code First 利用一种被称为约定(Conventions)优于配置(Configuration)的编程模式允许你使用自己的 domain classes 来表 ...
- Entity Framework Code First (二)Custom Conventions
---------------------------------------------------------------------------------------------------- ...
- Entity Framework Code First (一)Conventions
Entity Framework 简言之就是一个ORM(Object-Relational Mapper)框架. Code First 使得你能够通过C#的类来描述一个模型,模型如何被发现/检测就是通 ...
- Entity Framework Tutorial Basics(11):Code First
Code First development with Entity Framework: Entity Framework supports three different development ...
- Entity Framework Code First (七)空间数据类型 Spatial Data Types
声明:本文针对 EF5+, Visual Studio 2012+ 空间数据类型(Spatial Data Types)是在 EF5 中引入的,空间数据类型表现有两种: Geography (地理学上 ...
- Entity Framework Code First (四)Fluent API - 配置属性/类型
上篇博文说过当我们定义的类不能遵循约定(Conventions)的时候,Code First 提供了两种方式来配置你的类:DataAnnotations 和 Fluent API, 本文将关注 Flu ...
- Entity Framework Code First (八)迁移 Migrations
创建初始模型和数据库 在开始使用迁移(Migrations)之前,我们需要一个 Project 和一个 Code First Model, 对于本文将使用典型的 Blog 和 Post 模型 创建一个 ...
- Entity Framework Code First (六)存储过程
声明:本文只针对 EF6+ 默认情况下,Code First 对实体进行插入.更新.删除操作是直接在表上进行的,从 EF6 开始你可以选择使用存储过程(Stored Procedures) 简单实体映 ...
- Entity Framework Code First (五)Fluent API - 配置关系
上一篇文章我们讲解了如何用 Fluent API 来配置/映射属性和类型,本文将把重点放在其是如何配置关系的. 文中所使用代码如下 public class Student { public int ...
随机推荐
- python详细目录
python第一篇 第二篇.初识列表字典元祖循环 第三篇.内置方法 第四篇.编码解码 列表.元祖 第五篇.数据类型 第六篇 函数 第七篇.函数二 第八篇.递归.装饰器 第九篇 正则表达式 第十篇.模块 ...
- 20145229吴姗珊 《Java程序设计》第9周总结
20145229吴姗珊 <Java程序设计>第9周总结 教材学习内容总结 第十六章 整合数据库 JDBC入门 数据库本身是个独立运行的应用程序 撰写应用程序是利用通信协议对数据库进行指令交 ...
- scikit-learn笔记之初次接触
一.加载数据: 然后看一下有多少个特征和类别以及它们的名字: 二.数据可视化:: 由于该套数据集有4个特征,所以只能选取2个特征进行显示. 可见红色和绿色的点混在一起,所以再选择其他特征作为坐标轴: ...
- Spring Cloud之服务治理(注册发现)
服务治理SpringCloud Eureka 什么是服务治理 在传统rpc远程调用中,服务与服务依赖关系,管理比较复杂,所以需要使用服务治理,管理服务与服务之间依赖关系,可以实现服务调用.负载均衡.容 ...
- castle windsor学习----- Services and Components 两者的定义
- Jquery 取值,赋值学习总结
<h2>获取和设置文本框值:</h2> <input type="button" value="赋值文件框" id="v ...
- Linux学习过程中的简单命令
1.su su- 与 sudo (1) 普通用户和root转换:su 用户名或root 不知道root密码的情况下:普通 -> root:sudo su roo ...
- 关于_T()说明
#define _T(X) L##X _T()是MFC里的宏.VS支持两种编码方式ASCII和Unicode,前者是用单字节编码,只能表示0~255个字符.为了表示各个国家的字符,采用了UNICO ...
- leetcode 201. Bitwise AND of Numbers Range(位运算,dp)
Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...
- PostgreSQL正则及模糊查询优化
1.带前缀的模糊查询 ~'^abc' 可以使用btree索引优化 create index idx_info on table_name(info) 2.带后缀的模糊查询 ~'abc$' 可以使用 ...