Support PostgreSQL native inheritance

Open
#10,739 4 comments 40 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
25/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
csharp, postgresql
Domain
backend, databases

Research direction

Start by reading the PostgreSQL table inheritance documentation linked in the issue, including its caveats, and review the related Npgsql issue and Stack Overflow discussion. The requested outcome is EF Core support for mapping CLR inheritance to PostgreSQL native inheritance as an alternative to TPH, TPC, and TPT, including the described parent and child query behavior.

Written by the indexing model from the issue text.

Description

area-relational-mapping

PostgreSQL natively supports table inheritance in the database (see docs here, and also some current caveats). In theory EF Core could map CLR inheritance relations to this scheme as an additional alternative to TPH/TPC/TPT.

  • You use a special DDL to specify that one table (capitals) INHERITS FROM another table (cities).
  • The child table (capitals) implicitly contains fields from the parent (cities), so to get capitals you only need to select from the child table. In that sense it's like TPC.
  • However, tables need to be created for both child and parent, in that sense it's like TPT.
  • Selecting from the parent table will by default return children rows, so selecting from cities will return all cities. A special SELECT ... FROM ONLY CITIES syntax can return only the parents.

Requested in https://github.com/npgsql/Npgsql.EntityFrameworkCore.PostgreSQL/issues/59 and this SO.

Disclaimer: I'm opening this after a conversation with @divega in which he expressed interest, but I imagine the internal impact would be really non-trivial and beyond what you'd want to provide.

Dominant language
C#
Stars
14.8k
Forks
3.4k
Avg merge
2d 5h
Merged PRs (30d)
134

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dotnet/efcore

All issues in dotnet/efcore

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.