我有一个我试图在实体框架中实现的数据库。其中两个表具有多对多关系,似乎实体框架正在尝试创建一个不存在的列名。它坚持有一个:
列名“Shipment_Id”无效。
但是,我的代码或数据库中没有该列。这两个表是 Allocation 和 Shipment,由 ShipmentAllocation 联合。
以下是配置: 分配:
public AllocationConfiguration()
{
this.Property(x => x.Id).HasColumnName("AllocationId");
this.HasKey(x => x.Id);
this.Property(x => x.FulfillmentCenter).HasMaxLength(50);
this.Property(x => x.DateCreated);
this.Property(x => x.DateModified);
this.Property(x => x.ModifiedBy).HasMaxLength(50);
HasMany(x => x.OrderItems)
.WithOptional(x => x.Allocation)
.Map(x => x.MapKey("AllocationId"));
this.HasMany(a => a.Shipments)
.WithMany()
.Map(x =>
{
x.MapLeftKey("AllocationId");
x.MapRightKey("ShipmentId");
x.ToTable("ShipmentAllocation");
});
}
运输:
/// <summary>
/// Initializes a new instance of the <see cref="ShipmentConfiguration"/> class.
/// </summary>
public ShipmentConfiguration()
{
this.Property(x => x.Id).HasColumnName("ShipmentId");
this.HasKey(x => x.Id);
this.Property(x => x.DateCreated);
this.Property(x => x.DateModified);
this.Property(x => x.ModifiedBy).HasMaxLength(50);
this.HasMany(x => x.Cartons)
.WithRequired(x => x.Shipment)
.Map(x => x.MapKey("ShipmentId"));
}
我真的不确定出了什么问题,我已经搜索了 stackoverflow 和其他论坛,一切似乎都表明我所拥有的是正确的。