-
Notifications
You must be signed in to change notification settings - Fork 9
Open
Labels
enhancementNew feature or requestNew feature or requestlayer/databaseMeans some changes in the Database layerMeans some changes in the Database layer
Description
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
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestlayer/databaseMeans some changes in the Database layerMeans some changes in the Database layer