我有以下课程:
public class Bicycle
{
public int BicycleId { get; set; }
public DateTime YearOfManufacture { get; set; }
public int BicycleManufactuerId { get; set; }
public BicycleManufacturer BicycleManufacturer { get; set; }
}
public class BicycleManufacturer
{
public int BicycleManufacturerId { get; set; }
public string Description { get; set; }
}
每个Bicycle
必须有一个BicycleManufacturer
(1:1)。可能有一些BicycleManufacturer
与 any 无关Bicycle
。大多数将与多个Bicycle
实体相关联。
我有以下流畅的 API 代码来设置 FK 关系:
modelBuilder.Entity<Bicycle>()
.HasRequired(a => a.BicycleManufacturer)
.WithMany()
.HasForeignKey(u => u.BicycleManufactuerId);
这一切似乎都很好。但是,我真的很想从实体中删除该BicycleManufacturerId
属性。Bicycle
它只是在那里建立FK关系。如果我删除此属性,有没有办法可以创建正确的 FK 关系?