我有以下课程;
public partial class DriverType : Entity<int>
{
[Column("Id")]
[JsonProperty(PropertyName = "drivertypeid")]
public override int ID { get; set; }
[JsonProperty(PropertyName = "drivertype")]
public string Name { get; set; }
}
public partial class Driver : AuditableEntity<int>
{
[Key,Column("driverId", Order=0)]
[JsonProperty(PropertyName="driverid")]
public override int ID { get; set; }
[Key,Column("type", Order=1)]
[ForeignKey("DriverType")]
[JsonProperty(PropertyName="drivertypeid")]
public int DriverTypeId { get; set; }
public virtual DriverType DriverType { get; set; }
..... reduced for brevity
}
public partial class DriversToVehicle
{
[Column("id"), Key]
public int ID { get; set; }
[Column("driverId", Order = 0), ForeignKey("Driver")]
public int DriverID { get; set; }
public virtual Driver Driver { get; set; }
[Column("type", Order = 1), ForeignKey("Driver")]
public int DriverTypeId { get; set; }
[ForeignKey("DriverTypeId")]
public virtual DriverType DriverType { get; set; }
[Column("vehicleid")]
public int VehicleID { get; set; }
[ForeignKey("VehicleID")]
public virtual Vehicle Vehicle { get; set; }
}
以及
public partial class Appointment : AuditableEntity<int>
{
[Column("AppointmentId")]
[JsonProperty(PropertyName = "appointmentid")]
public override int ID { get; set; }
public DateTime Date { get; set; }
[Column("driverId", Order=0),ForeignKey("Driver")]
[JsonProperty(PropertyName = "driverid")]
public int? DriverID { get; set; }
[Column("type", Order = 1), ForeignKey("Driver")]
public int? DriverTypeId { get; set; }
[ForeignKey("DriverTypeId")]
public virtual DriverType DriverType { get; set; }
public virtual Driver Driver { get; set; }
再次针对该问题减少了上述代码。我现在遇到的问题是当我尝试运行迁移时,我得到以下Up()方法。
DropForeignKey("dbo.Appointment", "DriverID", "dbo.Driver");
DropForeignKey("dbo.InsurancePolicyDrivers", "Driver_ID", "dbo.Driver");
DropForeignKey("dbo.Driver", "Vehicle_ID", "dbo.Vehicles");
DropForeignKey("dbo.DriversToVehicles", "driverid", "dbo.Driver");
DropIndex("dbo.Appointment", new[] { "DriverID" });
DropIndex("dbo.Driver", new[] { "Vehicle_ID" });
DropIndex("dbo.DriversToVehicles", new[] { "driverid" });
DropIndex("dbo.InsurancePolicyDrivers", new[] { "Driver_ID" });
DropColumn("dbo.Driver", "driverId");
DropColumn("dbo.Driver", "driverId");
RenameColumn(table: "dbo.Driver", name: "id", newName: "driverId");
RenameColumn(table: "dbo.Driver", name: "Vehicle_ID", newName: "driverId");
DropPrimaryKey("dbo.Driver");
DropPrimaryKey("dbo.InsurancePolicyDrivers");
CreateTable(
"dbo.DriverTypes",
c => new
{
Id = c.Int(nullable: false, identity: true),
Name = c.String(),
IsArchived = c.Boolean(),
})
.PrimaryKey(t => t.Id);
AddColumn("dbo.Appointment", "type", c => c.Int());
AddColumn("dbo.DriversToVehicles", "type", c => c.Int(nullable: false));
AddColumn("dbo.InsurancePolicyDrivers", "Driver_DriverTypeId", c => c.Int(nullable: false));
AlterColumn("dbo.Driver", "driverId", c => c.Int(nullable: false));
AlterColumn("dbo.Driver", "driverId", c => c.Int(nullable: false));
AddPrimaryKey("dbo.Driver", new[] { "driverId", "type" });
AddPrimaryKey("dbo.InsurancePolicyDrivers", new[] { "InsurancePolicy_ID", "Driver_ID", "Driver_DriverTypeId" });
CreateIndex("dbo.Appointment", new[] { "driverId", "type" });
CreateIndex("dbo.Driver", "driverId");
CreateIndex("dbo.Driver", "type");
CreateIndex("dbo.DriversToVehicles", new[] { "driverId", "type" });
CreateIndex("dbo.InsurancePolicyDrivers", new[] { "Driver_ID", "Driver_DriverTypeId" });
AddForeignKey("dbo.Driver", "type", "dbo.DriverTypes", "Id", cascadeDelete: true);
AddForeignKey("dbo.Appointment", "type", "dbo.DriverTypes", "Id");
AddForeignKey("dbo.DriversToVehicles", "type", "dbo.DriverTypes", "Id", cascadeDelete: true);
AddForeignKey("dbo.Appointment", new[] { "driverId", "type" }, "dbo.Driver", new[] { "driverId", "type" });
AddForeignKey("dbo.InsurancePolicyDrivers", new[] { "Driver_ID", "Driver_DriverTypeId" }, "dbo.Driver", new[] { "driverId", "type" });
AddForeignKey("dbo.Driver", "driverId", "dbo.Vehicles", "id", cascadeDelete: true);
AddForeignKey("dbo.DriversToVehicles", new[] { "driverId", "type" }, "dbo.Driver", new[] { "driverId", "type" }, cascadeDelete: true);
您可以看到它尝试重新创建同名的重复列?我想这是因为它试图在这里设置外键吗?