{"id":20365746,"url":"https://github.com/eliasprates/inheritanceefcore","last_synced_at":"2026-05-19T04:36:44.425Z","repository":{"id":219569837,"uuid":"749343122","full_name":"eliasprates/inheritanceEfCore","owner":"eliasprates","description":"Inheritance in EF Core - Herança no EF Core - TPH - TPC -TPT - Fluent API","archived":false,"fork":false,"pushed_at":"2024-01-28T11:29:06.000Z","size":15,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-11T04:02:31.440Z","etag":null,"topics":["dependency-injection","dotnet","entity-framework-core","fluent-api","inheritance","tpc","tph","tpt"],"latest_commit_sha":null,"homepage":"https://learn.microsoft.com/en-us/ef/core/modeling/inheritance","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eliasprates.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2024-01-28T09:55:49.000Z","updated_at":"2024-09-08T12:29:36.000Z","dependencies_parsed_at":"2024-01-28T13:28:28.375Z","dependency_job_id":"5881a207-35b1-441b-afbd-4cb9a619a61d","html_url":"https://github.com/eliasprates/inheritanceEfCore","commit_stats":null,"previous_names":["eliasprates/inheritanceefcore"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/eliasprates/inheritanceEfCore","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eliasprates%2FinheritanceEfCore","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eliasprates%2FinheritanceEfCore/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eliasprates%2FinheritanceEfCore/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eliasprates%2FinheritanceEfCore/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eliasprates","download_url":"https://codeload.github.com/eliasprates/inheritanceEfCore/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eliasprates%2FinheritanceEfCore/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33201977,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-18T09:27:30.708Z","status":"online","status_checked_at":"2026-05-19T02:00:06.763Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dependency-injection","dotnet","entity-framework-core","fluent-api","inheritance","tpc","tph","tpt"],"created_at":"2024-11-15T00:19:56.128Z","updated_at":"2026-05-19T04:36:44.397Z","avatar_url":"https://github.com/eliasprates.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# (PT-BR)\n# Estratégias de Herança no Entity Framework Core\n\nEste repositório demonstra as diferentes abordagens de herança utilizadas no Entity Framework Core: Table Per Hierarchy (TPH), Table Per Type (TPT) e Table Per Concrete class (TPC). Cada abordagem tem suas próprias características e é adequada para diferentes cenários.\n\n## Table Per Hierarchy (TPH)\n\nNa abordagem TPH, todas as classes na hierarquia de herança são mapeadas para uma única tabela. A tabela possui uma coluna discriminadora para diferenciar entre os tipos.\n\n### Estrutura da Tabela TPH\n\n#### Tabela: Vehicles\n\n| Column        | Type    | Notas                            |\n|---------------|---------|----------------------------------|\n| Id            | int     | Chave Primária                   |\n| Model         | string  |                                  |\n| Year          | int     |                                  |\n| Type          | string  | Discriminador (Car, Motorcycle)  |\n| NumberOfDoors | int     | NULL para motocicletas           |\n| HasFairing    | boolean | NULL para carros                 |\n\n## Table Per Type (TPT)\n\nA abordagem TPT mapeia cada classe na hierarquia de herança para sua própria tabela, com cada classe derivada tendo sua própria chave primária e uma chave estrangeira referenciando a tabela da classe base.\n\n### Estrutura das Tabelas TPT\n\n#### Tabela: Vehicles\n\n| Column        | Type    | Notas                            |\n|---------------|---------|----------------------------------|\n| Id            | int     | Chave Primária                   |\n| Model         | string  |                                  |\n| Year          | int     |                                  |\n\n#### Tabela: Cars\n\n| Column        | Type    | Notas                            |\n|---------------|---------|----------------------------------|\n| Id            | int     | Chave Primária                   |\n| VehicleId     | int     | Chave Estrangeira para Vehicles  |\n| NumberOfDoors | int     |                                  |\n\n#### Tabela: Motorcycles\n\n| Column     | Type    | Notas                               |\n|---------------|---------|----------------------------------|\n| Id            | int     | Chave Primária                   |\n| VehicleId     | int     | Chave Estrangeira para Vehicles  |\n| HasFairing    | boolean |                                  |\n\n## Table Per Concrete class (TPC)\n\nNa abordagem TPC, cada classe concreta na hierarquia de herança é mapeada para sua própria tabela, e a classe base não é representada.\n\n### Estrutura das Tabelas TPC\n\n#### Tabela: Cars\n\n| Column        | Type   | Notas                            |\n|---------------|--------|----------------------------------|\n| Id            | int    | Chave Primária                   |\n| Model         | string |                                  |\n| Year          | int    |                                  |\n| NumberOfDoors | int    |                                  |\n\n#### Tabela: Motorcycles\n\n| Column        | Type    | Notas                            |\n|---------------|---------|----------------------------------|\n| Id            | int     | Chave Primária                   |\n| Model         | string  |                                  |\n| Year          | int     |                                  |\n| HasFairing    | boolean |                                  |\n\n---\n\nPara mais informações sobre como implementar cada uma dessas abordagens no Entity Framework Core, consulte a documentação oficial.\n\n\n# (EN-US)\n# Inheritance Strategies in Entity Framework Core\n\nThis repository demonstrates the different inheritance approaches used in Entity Framework Core: Table Per Hierarchy (TPH), Table Per Type (TPT), and Table Per Concrete class (TPC). Each approach has its own characteristics and is suitable for different scenarios.\n\n## Table Per Hierarchy (TPH)\n\nIn the TPH approach, all classes in the inheritance hierarchy are mapped to a single table. The table has a discriminator column to differentiate between the types.\n\n### TPH Table Structure\n\n#### Tabela: Vehicles\n\n| Column        | Type    | Notes                            |\n|---------------|---------|----------------------------------|\n| Id            | int     | Primary Key                      |\n| Model         | string  |                                  |\n| Year          | int     |                                  |\n| Type          | string  | Discriminator (Car, Motorcycle)  |\n| NumberOfDoors | int     | NULL for motorcycles             |\n| HasFairing    | boolean | NULL for cars                    |\n\n## Table Per Type (TPT)\n\nThe TPT approach maps each class in the inheritance hierarchy to its own table, with each derived class having its own primary key and a foreign key referencing the base class table.\n\n### TPT Table Structures\n\n#### Table: Vehicles\n\n| Column        | Type    | Notes                            |\n|---------------|---------|----------------------------------|\n| Id            | int     | Primary Key                      |\n| Model         | string  |                                  |\n| Year          | int     |                                  |\n\n#### Table: Cars\n\n| Column        | Type    | Notes                            |\n|---------------|---------|----------------------------------|\n| Id            | int     | Primary Key                      |\n| VehicleId     | int     | Foreign Key to Vehicles          |\n| NumberOfDoors | int     |                                  |\n\n#### Table: Motorcycles\n\n| Column     | Type    | Notes                               |\n|---------------|---------|----------------------------------|\n| Id            | int     | Primary Key                      |\n| VehicleId     | int     | Foreign Key to Vehicles          |\n| HasFairing    | boolean |                                  |\n\n## Table Per Concrete class (TPC)\n\nIn the TPC approach, each concrete class in the inheritance hierarchy is mapped to its own table, and the base class is not represented.\n\n### TPC Table Structures\n\n#### Table: Cars\n\n| Column        | Type    | Notes                            |\n|---------------|---------|----------------------------------|\n| Id            | int     | Primary Key                      |\n| Model         | string  |                                  |\n| Year          | int     |                                  |\n| NumberOfDoors | int     |                                  |\n\n#### Table: Motorcycles\n\n| Column        | Type    | Notes                            |\n|---------------|---------|----------------------------------|\n| Id            | int     | Primary Key                      |\n| Model         | string  |                                  |\n| Year          | int     |                                  |\n| HasFairing    | boolean |                                  |\n\n---\n\nFor more information on how to implement each of these approaches in Entity Framework Core, consult the official documentation.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feliasprates%2Finheritanceefcore","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feliasprates%2Finheritanceefcore","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feliasprates%2Finheritanceefcore/lists"}