Skip to content

Why is a type discriminator not supported in TPT mapping strategy? #35286

Closed as not planned
@gumbarros

Description

While configuring an EF Core entity using Table-per-Type (TPT) mapping strategy, I attempted to set up a type discriminator for easier identification of the derived entity types. However, it seems this feature is not supported when using TPT. Below is the configuration code I used:

modelBuilder.Entity<MenuItemEntity>()
    .ToTable("MenuItem", Schema)
    .UseTptMappingStrategy()
    .HasDiscriminator<MenuItemType>("Type")
    .HasValue<FileMenuItemEntity>(MenuItemType.File)
    .HasValue<FolderMenuItemEntity>(MenuItemType.Folder)
    .HasValue<FormElementMenuItemEntity>(MenuItemType.FormElement)
    .HasValue<PluginMenuItemEntity>(MenuItemType.Plugin)
    .HasValue<PowerBIMenuItemEntity>(MenuItemType.PowerBI)
    .HasValue<ReportMenuItemEntity>(MenuItemType.Report)
    .HasValue<UrlMenuItemEntity>(MenuItemType.Url);

Upon running the application, the configuration fails, and after reviewing the documentation, it seems TPT does not allow a discriminator column.

System.InvalidOperationException: The mapping strategy 'TPT' specified on 'MenuItemEntity' is not supported for entity types with a discriminator.

This raises the following questions:

  1. Why is a discriminator column not supported when using the TPT mapping strategy? I want to have this discriminator column at MenuItemEntity for SQL reports outside my app.
  2. Are there any underlying technical limitations or design decisions behind this?

Understanding the rationale behind this limitation would be helpful for designing better solutions or workarounds for applications that need TPT with type discriminators.

Activity

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

Metadata

Assignees

No one assigned

    Labels

    closed-out-of-scopeThis is not something that will be fixed/implemented and the issue is closed.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions