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

Add metadata support for TPC #27628

Merged
merged 1 commit into from
Mar 15, 2022
Merged

Add metadata support for TPC #27628

merged 1 commit into from
Mar 15, 2022

Conversation

AndriySvyryd
Copy link
Member

@AndriySvyryd AndriySvyryd commented Mar 12, 2022

Part of #3170

  • Added UseTpcMappingStrategy and UseTptMappingStrategy, calling either maps all derived to different tables/views
  • Also just calling ToTable on a non-root type maps the hierarchy using TPT
  • Throw for ToTable on abstract entity type if TPC
  • If an entity type is not mapped to a table in TPT then the properties are mapped to the columns in the tables corresponding to its direct descendants and the identifying FK on the derived types is created pointing to the next mapped base type
  • Only create check constraints on the first mapped type in TPT
  • Added support for TPT and TPC for default mappings
  • Warn that FKs that point to a TPC entity type won't be created in the database
  • Warn when a PK property is store generated in TPC

/// </summary>
/// <param name="entityType">The entity type.</param>
/// <returns>The mapping strategy for the derived types.</returns>
public static string? GetMappingStrategy(this IReadOnlyEntityType entityType)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can a mapping strategy be applied to the entire model rather than to each entity type?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not yet. #27642

@smitpatel
Copy link
Member

        root.Builder.HasNoDiscriminator();

What would happen in scenario when user configures discriminator and also applies TPT/TPC mapping strategy explicitly?


Refers to: src/EFCore.Relational/Metadata/Conventions/EntityTypeHierarchyMappingConvention.cs:110 in db75fae. [](commit_id = db75fae, deletion_comment = False)

{
var columnName = property.GetColumnBaseName();
if (columnName == null)
var mappedTableName = isTph ? entityType.GetRootType().Name : mappedType.Name;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would have loved if the variable didn't use table in the name.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, me too...

@AndriySvyryd
Copy link
Member Author

What would happen in scenario when user configures discriminator and also applies TPT/TPC mapping strategy explicitly?

We throw NonTphMappingStrategy

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

Successfully merging this pull request may close these issues.

3 participants