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

Create a consistent relational model API #12846

Closed
4 tasks done
AndriySvyryd opened this issue Jul 31, 2018 · 7 comments · Fixed by #19971
Closed
4 tasks done

Create a consistent relational model API #12846

AndriySvyryd opened this issue Jul 31, 2018 · 7 comments · Fixed by #19971
Labels
area-model-building closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. providers-beware type-enhancement
Milestone

Comments

@AndriySvyryd
Copy link
Member

AndriySvyryd commented Jul 31, 2018

Add a new API that allows to configure and read relational mapping information. Adding this abstraction layer would allow to make the mapping more flexible and the implementation more efficient without additional changes to the consumers.

Some examples of queries that would benefit from this:

  • Get all columns for a table
  • Get all entity types mapped to a table
  • Get all properties mapped to a column
  • Get the database object that a navigation/relationship is mapped to

New mapping scenarios that this would be allow:

  • Mapping an entity type to more than one table
  • Different relational configuration for properties mapped to more than one column
  • Different mapping for migrations, query and update pipeline

Tasks:

  • Add metadata implementation
  • Port migrations
  • Port update pipeline
  • Port query
@AndriySvyryd
Copy link
Member Author

AndriySvyryd commented Jan 31, 2020

These are the entity type mappings that can be potentially used for each aspect of EF:

Nothing Table View Def Query Sproc Function
Migrations ✔️ ✔️ ✔️ ✔️ ✔️
Query ✔️ ✔️ ✔️ ✔️ ✔️
CUD ✔️ ✔️ ✔️ ✔️
Bulk CUD ✔️ ✔️
Scaffolding ✔️ ✔️ ✔️

With table mapping being any of the following:

  • Hierarchy mapping strategy (can only use one per hierarachy):
    • TPH: all types in a single table* with a discriminator
    • TPT: each entity type is stored in a table* with columns for only the non-inherited properties, usually linked by an FK in the database
    • TPC: each entity type is stored in a separate table*
    • Inherited Tables (PostgreSQL): Like TPT, but the tables for the derived types also have all columns
  • Row mapping strategies (each entity type can have one or more if it doesn’t interfere with other mappings in the hierarchy):
    • Table splitting: multiple entities per row, linked by a metadata-only FK
    • Entity splitting: entity is split across multiple tables*, usually linked by an FK in the database

The following features could be implemented by using the representation described below:

Limitations:

  • Only one inheritance mapping strategy can be used per hierarchy
  • While hierarchy mapping strategies can also be used when mapping to views or functions they can't be mixed in with tables in the same hierarchy

AndriySvyryd added a commit that referenced this issue Feb 11, 2020
Introduce IModelFinalizedConvention that don't change the model

Part of #12846
AndriySvyryd added a commit that referenced this issue Feb 11, 2020
Introduce IModelFinalizedConvention that don't change the model

Part of #12846
AndriySvyryd added a commit that referenced this issue Feb 11, 2020
Introduce IModelFinalizedConvention that don't change the model

Part of #12846
AndriySvyryd added a commit that referenced this issue Feb 12, 2020
Use the new model in migrations and update pipeline

Part of #12846, #2725, #8258, #15671, #17270
@AndriySvyryd
Copy link
Member Author

AndriySvyryd commented Feb 12, 2020

The core design:

  • Once the model is built and validated the relational model will be generated and stored as annotations.
  • When the model is used to find the mapping to use, the possible mapping types will be queried in a specific priority order. For example in Query we would call entityType.GetFunctionMappings() if that returns no result we'll call entityType.GetDefiningQueryMappings(), then entityType.GetViewMappings() and finally entityType.GetTableMappings().
    image

This is how the metadata objects will look for each type of mapping strategy:

TPH

TPH

TPC

TPC

TPT

TPT

Table inheritance

image

Table splitting

image

Entity splitting

image

AndriySvyryd added a commit that referenced this issue Feb 13, 2020
Use the new model in migrations and update pipeline

Part of #12846, #2725, #8258, #15671, #17270
@AndriySvyryd AndriySvyryd added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Feb 15, 2020
@AndriySvyryd AndriySvyryd removed their assignment Feb 15, 2020
@roji
Copy link
Member

roji commented Feb 17, 2020

While syncing EFCore.PG, ran into the breaking change in 3574cfb (IModelFinalizedConvention/IModelFinalizingConvention), consider opening a separate issue for that (or documenting) as it's provider-breaking.

@ajcvickers
Copy link
Member

@roji I thought we talked about this and decided providers-beware was enough. What am I missing?

@roji
Copy link
Member

roji commented Feb 18, 2020

Just that this is an extremely wide issue (maybe an epic really), and this convention change doesn't necessarily seem part of the relational model. If we feel this one issue should cover everything, maybe a small list of breaking changes on it would help track things?

@AndriySvyryd
Copy link
Member Author

That's why it was changed in a separate PR #19872
Do you normally look at fixed issues or PRs for providers-beware?

@roji
Copy link
Member

roji commented Feb 18, 2020

Sometimes :) I do it occasionally when something breaks when I try syncing to the latest, to help understand what's going on. Not critical if you don't feel it's worth it.

AndriySvyryd added a commit that referenced this issue Feb 19, 2020
Use the new model in the query pipeline

Fixes #12846
AndriySvyryd added a commit that referenced this issue Feb 20, 2020
Use the new model in the query pipeline

Fixes #12846
AndriySvyryd added a commit that referenced this issue Feb 20, 2020
Use the new model in the query pipeline

Fixes #12846
@ajcvickers ajcvickers modified the milestones: 5.0.0, 5.0.0-preview2 Mar 13, 2020
@ajcvickers ajcvickers modified the milestones: 5.0.0-preview2, 5.0.0 Nov 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-model-building closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. providers-beware type-enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants