2
我有一个数据库,我试图在实体框架中实现。其中两个表具有多对多的关系,看起来实体框架试图创建一个不存在的列名。它坚持存在:实体框架:“无效的列名称”与多对多的映射错误
无效的列名'Shipment_Id'。
但是,在我的代码或数据库中没有任何地方存在那个列。这两个表是分配和发货,由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"));
}
我真的不知道什么是错的,我已经走遍计算器和其他论坛,一切似乎表明,我所拥有的是正确的。