C# 实体框架代码优先,迁移错误
我的asp.net mvc应用程序中有4个模型,在编写Update Database命令时出错 在表“约会”上引入外键约束“FK_dbo.Appointments_dbo.DoctorId”可能会导致循环或多个级联路径。指定“在删除时不执行操作”或“在更新时不执行操作”,或修改其他外键约束。 无法创建约束或索引。请参阅前面的错误C# 实体框架代码优先,迁移错误,c#,asp.net,model-view-controller,C#,Asp.net,Model View Controller,我的asp.net mvc应用程序中有4个模型,在编写Update Database命令时出错 在表“约会”上引入外键约束“FK_dbo.Appointments_dbo.DoctorId”可能会导致循环或多个级联路径。指定“在删除时不执行操作”或“在更新时不执行操作”,或修改其他外键约束。 无法创建约束或索引。请参阅前面的错误 问题出在哪里?看看这个,看看它是否有帮助: public class Appointment { public Appointment() {
问题出在哪里?看看这个,看看它是否有帮助:
public class Appointment
{
public Appointment()
{
Status = "UnCompleted";
}
[Display(Name = "Appointment Id")]
[Key]
public int AppoiId { get; set; }
[Display(Name = "Patient Id")]
public int PatientId { get; set; }
[ForeignKey("PatientId")]
public virtual Patient Patient { get; set; }
[Display(Name = "Clinic Id")]
public int ClinicId { get; set; }
[ForeignKey("ClinicId")]
public virtual Clinic Clinic { get; set; }
[Display(Name = "Doctor Id")]
public int DoctorId { get; set; }
[ForeignKey("DoctorId")]
public virtual Doctor Doctor { get; set; }
[Required]
[DataType(DataType.Date)]
public string Date { get; set; }
[Required]
[DataType(DataType.Time)]
public string Time { get; set; }
public string Status { get; set; }
}`public class Doctor
{
[Display(Name = "Doctor Id")]
[Key]
public int DoctorId { get; set; }
[Required(ErrorMessage ="Please Enter First Name")]
[Display(Name ="First Name")]
public string FirstName { get; set; }
[Required(ErrorMessage = "Please Enter Last Name")]
[Display(Name = "Last Name")]
public string LastName { get; set; }
[Required(ErrorMessage ="Please Enter Email")]
[EmailAddress]
public string Email { get; set; }
[Required(ErrorMessage ="Please Enter Password")]
[Display(Name ="Password")]
[DataType(DataType.Password)]
[NotMapped]
public string Password { get; set; }
[Required(ErrorMessage = "Please Enter Phone number")]
[Display(Name ="Phone")]
public string Phone { get; set; }
public int ClinicId { get; set; }
[ForeignKey("ClinicId")]
public virtual Clinic Clinic { get; set; }
}`public class Clinic
{
[Key]
[Display(Name = "Clinic Id")]
public int ClinicId { get; set; }
[Required(ErrorMessage ="Please Enter Clinic Name")]
[Display(Name = "Clinic Name")]
public string ClinicName { get; set; }
[Display(Name ="No. of Doctors")]
public int No_Doctors { get; set; }
[Required]
[Display(Name ="Available Time")]
public string Available_time { get; set; }
}`public class Report
{
[Key]
public int ReportId { get; set; }
public int AppoiId { get; set; }
[ForeignKey("AppoiId")]
public virtual Appointment Appointment { get; set; }
public int PatientId { get; set; }
[ForeignKey("PatientId")]
public virtual Patient Patient { get; set; }
public int DoctorId { get; set; }
[ForeignKey("DoctorId")]
public virtual Doctor Doctor { get; set; }
[Required]
public string Symptoms { get; set; }
[Required]
public string Diagnosis { get; set; }
public string Date { get; set; }
[Required]
[Display(Name ="Report Type")]
public Type ReportType { get; set; }
}`