我一直在閱讀關於EF代碼的SO帖子首先生成重複的外鍵,並試圖將解決方案應用於我的代碼,但無法修復我的代碼。EF代碼同一表第一個重複的外鍵
這裏是我的班
public class Schedule
{
public int Id { get; set; }
public ICollection<Appointment> Appointments { get; set; }
}
public class Appointment
{
public int Id { get; set; }
public Schedule Schedule { get; set; }
}
public class ScheduleConfiguration : EntityTypeConfiguration<Schedule>
{
public ScheduleConfiguration()
{
HasKey(s => s.Id);
Property(s => s.Id).HasColumnName("SCHEDULEID");
ToTable("SCHEDULES");
}
}
public class AppointmentConfiguration : EntityTypeConfiguration<Appointment>
{
public AppointmentConfiguration()
{
HasKey(a => a.Id);
Property(a => a.Id).HasColumnName("APPOINTMENTID");
HasRequired(a => a.Schedule).WithMany().Map(x => x.MapKey("SCHEDULEID"));
ToTable("APPOINTMENTS");
}
}
這在appointments
表生成兩個外鍵即SCHEDULEID
和Schedule_Id1
。
我怎麼能告訴EF不創建Schedule_Id1
現在FK是Schedule_Id我想成爲SCHEDULEID – ZedBee