你的位置:首页 > 软件开发 > ASP.net > EF继承关系映射

EF继承关系映射

发布时间:2015-05-26 00:00:48
继承映射策略的三种策略 There are following three different approaches to represent an inheritance hierarchy in Code First: Table per Hierarchy (TPH) ...

继承映射策略的三种策略

There are folloget='_blank'>wing three different approaches to represent an inheritance hierarchy in Code First:

  1. Table per Hierarchy (TPH): This approach suggests one table for entire class inheritance hierarchy. Table includes discriminator column which distinguish between inheritance classes. This is a default inheritance mapping strategy in Entity Framework.
  2. Table per Type (TPT): This approach suggests seperate table for each domain class.
  3. 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 concrete class.

Code First 有以下三种不同的方法来表示继承层次结构:

  1. 每个层次结构一张表 (TPH): 这种方法表明,为整个类继承层次结构一个表。表包括鉴别器列(discriminator )的区分继承类。这是在实体框架中的默认继承映射策略。
  2. 每个类型一张表 (TPT): 这种方法显示单独的表中为每个域类。
  3. 每个具体类 一张表(TPC) : 这种方法显示一个表为一个具体的类,而不是抽象类。因此如果你继承的抽象类在多个具体的类然后抽象类的属性中将每个表具体类的一部分。

 

EF继承关系映射

EF继承关系映射

----------------------------------------------------------------------------

EF继承关系映射

EF继承关系映射

 

---------------------------------------------------

EF继承关系映射

EF继承关系映射

 

三种策略的适用场景

I want to emphasize that there is no one single "best strategy fits all scenarios" exists. As you saw, each of the approaches have their own advantages and drawbacks. Here are some rules of thumb to identify the best strategy in a particular scenario:

  1. If you don’t require polymorphic associations or queries, lean toward TPC—in other words, if you never or rarely query for BillingDetails and you have no class that has an association to BillingDetail base class. I recommend TPC (only) for the top level of your class hierarchy, where polymorphism isn’t usually required, and when modification of the base class in the future is unlikely.

     

    海外公司注册、海外银行开户、跨境平台代入驻、VAT、EPR等知识和在线办理:https://www.xlkjsw.com

    原标题:EF继承关系映射

    关键词:映射

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