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

TPH with owned types #35

Open
LeftTwixWand opened this issue Feb 20, 2023 · 0 comments
Open

TPH with owned types #35

LeftTwixWand opened this issue Feb 20, 2023 · 0 comments
Labels
enhancement New feature or request layer/database Means some changes in the Database layer

Comments

@LeftTwixWand
Copy link
Owner

LeftTwixWand commented Feb 20, 2023

I'm trying to store events in the Warehouses table per product id.
And all the events are inherited from WarehouseEventBase.
But now it's impossible to have TPH (Table Per Hierarchy) with owned types, like this:

internal sealed class WarehouseEntityTypeConfiguration : IEntityTypeConfiguration<Warehouse>
{
    public void Configure(EntityTypeBuilder<Warehouse> builder)
    {
        builder.ToTable("Warehouses");

        builder.HasKey(warehouse => warehouse.ProductId);

        builder.Property(warehouse => warehouse.ProductId)
            .HasColumnName(nameof(Product.Id))
            .HasConversion(id => id.Value, value => new ProductId(value));

        builder.OwnsMany(warehouse => warehouse.DomainEvents, navigationBuilder =>
        {
            navigationBuilder.UsePropertyAccessMode(PropertyAccessMode.Field);
        });
    }
}
internal sealed class WarehouseEventBaseTypeConfiguration : IEntityTypeConfiguration<WarehouseEventBase>
{
    public void Configure(EntityTypeBuilder<WarehouseEventBase> builder)
    {
        builder.HasDiscriminator<string>(nameof(WarehouseEventBase))
            .HasValue<WarehouseCreatedEvent>(nameof(WarehouseCreatedEvent))
            .HasValue<ProductsShippedEvent>(nameof(ProductsShippedEvent))
            .HasValue<ProductsMissedEvent>(nameof(ProductsMissedEvent))
            .HasValue<ProductsReceivedEvent>(nameof(ProductsReceivedEvent));
    }
}

This behavior should be implemented as soon as the feature will be added to ef core 8.
Related issue: dotnet/efcore#9630

download

@LeftTwixWand LeftTwixWand added enhancement New feature or request layer/database Means some changes in the Database layer labels Mar 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request layer/database Means some changes in the Database layer
Projects
None yet
Development

No branches or pull requests

1 participant