Inheritance Strategy (Inheritance Policy) [EFcode-first series], strategyfirst

Source: Internet
Author: User

Inheritance Strategy (Inheritance Policy) [EFcode-first series], strategyfirst

We already know in the article code-first conventions that Code-First creates a data table for each specific class.

However, you can use the inheritance design domain class by yourself. The object-oriented technology includes the relationship between "has a" and "is a", that is, what is, what is, and the relationship, however, before SQL-based entities and data table sets, there is only a "has a" relationship. The database management System (SQL database management systems) does not support inheritance types. So, how do you map object-oriented domain entities with relational databases ???

 

There are three methods to show inheritance in Code-First:

  • Table per Hierarchy (TPH ):This approach suggests one table for the entire class inheritance hierarchy. Table partition des discriminator column which distinguishes between inheritance classes. This isDefaultInheritance mapping strategy in Entity Framework.

In this way, a table is recommended as the inheritance hierarchy of the entire class. This table contains listening columns that can be distinguished from inherited classes. This is the default inheritance policy in EF.

  • Table per Type (TPT ):This approach suggests a separate table for each domain class.

In this way, we recommend that you create 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.

In this way, we recommend that you create a table for each specific class, except for the abstract class. Therefore, if you inherit an abstract class from multiple concrete classes, the attributes of this abstract class will be part of the attributes of each specific class (table.

 

We do not have much in-depth understanding here. If you want to learn more about the technology, please refer:

We are not going into detail here. Visit the following reference link for more detailed information:

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.

In the previous sections, we have seen the default Code-First Convention. In the following section, let's learn how to configure our domain classes to break the default convention.

PS: the inherited part. I will go into the technology and translate it later. Thank you for your support !!!

 

Attached directory:

  • What is Code First?
  • Simple Code First example
  • Code-First Convention
  • DB Initialization (Database Initialization)
  • Inheritance Strategy (Inheritance Policy)
  • Configure Domain Classes (configuration Domain class)
  • DataAnnotations (Data annotation)
  • Fluent API
  • Configure One-to-One (Configure a One-to-One relationship)
  • Configure One-to-multiple (Configure One-to-multiple relationships)
  • Configure allow-to-Configure (Configure Many-to-Many relationships)
  • Move deployments (data migration)
  • DB Initialization Strategy (Database Initialization Policy)
  • ... To be continued .....

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.