你的位置:首页 > 软件开发 > ASP.net > Inheritance Strategy(继承策略)【EFcode

Inheritance Strategy(继承策略)【EFcode

发布时间:2015-12-05 21:00:31
我们已经在code-first 约定一文中,已经知道了Code-First为每一个具体的类,创建数据表。但是你可以自己利用继承设计领域类,面向对象的技术包含“has a”和“is a”的关系即,有什么 ...

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

但是你可以自己利用继承设计领域类,get='_blank'>面向对象的技术包含“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:这个继承的部分,我后面会深入看下里面的技术,然后翻译出来。请大家多多支持!!!

 

附上目录:

  • 什么是Code First
  • 简单的Code First例子
  • Code-First 约定
  • DB Initialization(数据库初始化)
  • Inheritance Strategy(继承策略)
  • Configure Domain Classes(配置领域类)
  • DataAnnotations(数据注解)
  • Fluent API
  • Configure One-to-One(配置一对一关系)
  • Configure One-to-Many(配置一对多关系)
  • Configure Many-to-Many(配置多对多关系)
  • Move Configurations(数据迁移)
  • DB Initialization Strategy(数据库初始化策略)
  • ...待续.....

 


原标题:Inheritance Strategy(继承策略)【EFcode

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

可能感兴趣文章

我的浏览记录