Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support PostgreSQL native inheritance #10739

Open
Tracked by #22953
roji opened this issue Jan 21, 2018 · 4 comments
Open
Tracked by #22953

Support PostgreSQL native inheritance #10739

roji opened this issue Jan 21, 2018 · 4 comments

Comments

@roji
Copy link
Member

roji commented Jan 21, 2018

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 npgsql/efcore.pg#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.

@roji
Copy link
Member Author

roji commented May 30, 2019

Note that table inheritance is no longer recommended by PostgreSQL: https://wiki.postgresql.org/wiki/Don%27t_Do_This#Don.27t_use_table_inheritance

@brianjlowry
Copy link

I don't understand why this "fad" is a bad idea. How would you map foreign keys/tables to hierarchical domain models?

@ajcvickers
Copy link
Contributor

Make sure to talk to @roji before starting any work on this.

@AndriySvyryd
Copy link
Member

To allow this and other similar patterns the creation of RelationalModel needs to be factored out to a service that the providers can override.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants