1

我需要做以下映射

类图 OrderItem 将映射到 tbl_order_item

OrderItemCustomization 将映射到 tbl_order_item_customization

我在 tbl_order_item_customization 中有一个列 [cd_order_item],它是外键

问题是我如何映射之间的关系

CardOrderItem -> CardOrderItemCustomization

CustomCardOrderItem -> CustomCardOrderItemCustomization

我试过这个

public class OrderItemConfiguration : EntityTypeConfiguration<OrderItem>
{
  public OrderItemConfiguration()
  {
    ToTable("tbl_order_item");
    HasKey(i => i.Id);
    Property(i => i.Id).HasColumnName("cd_order_items");
    HasRequired(i => i.Order).WithMany(o => o.Items).Map(m => m.MapKey("cd_order"));
    HasRequired(i => i.Product).WithMany().Map(m => m.MapKey("cd_product"));
    Property(i => i.Quantity).HasColumnName("cd_quantity");
    Property(i => i.UnitAmount).HasColumnName("vl_item").HasColumnType("money");
    Property(i => i.TotalAmount).HasColumnName("vl_total").HasColumnType("money");
    Property(i => i.DiscountAmount).HasColumnName("vl_discount");
    Property(i => i.CostAmount).HasColumnName("vl_cost_price");
    Property(i => i.NetAmount).HasColumnName("vl_net");
    HasRequired(i => i.Status).WithMany().Map(m => m.MapKey("cd_status"));
    Property(i => i.IsActive).HasColumnName("fl_active");
  }
}

public class AbstractCardOrderItemConfiguration :   EntityTypeConfiguration<AbstractCardOrderItem>
{
  public AbstractCardOrderItemConfiguration()
  {
    Property(i => i.IsVirtual).HasColumnName("fl_virtual");
    Property(i => i.CardType).HasColumnName("cd_card_type").IsOptional();
    Property(i => i.Document).HasColumnName("nr_document");
    HasRequired(i => i.Package).WithRequiredPrincipal().Map(m =>   m.MapKey("cd_order_item_base"));
  }
}

public class CardOrderItemConfiguration : EntityTypeConfiguration<CardOrderItem>
{
  public CardOrderItemConfiguration()
  {
    HasRequired(i => i.CardOrderItemCustomization).WithRequiredPrincipal().Map(m =>   m.MapKey("cd_order_items"));
  }
}

public class CustomCardOrderItemConfiguration :   EntityTypeConfiguration<CustomCardOrderItem>
{
  public CustomCardOrderItemConfiguration()
  {
    HasRequired(i =>   i.CardWithCustomPhotoOrderItemCustomization).WithRequiredPrincipal().Map(m =>   m.MapKey("cd_order_items"));
  }
}

但这给了我一个错误:

在模型生成期间检测到一个或多个验证错误:

cd_order_items:名称:类型中的每个属性名称必须是唯一的。属性名称“cd_order_items”已定义。

有什么方法可以实现所需的映射?

4

0 回答 0