Entity Framework Code First, Ошибка в миграции - PullRequest
2 голосов
/ 04 мая 2020

В моем приложении asp. net mvc есть 4 модели, и я получаю сообщение об ошибке при написании команды Update-Database

Введение ограничения FOREIGN KEY 'FK_dbo.Appointments_dbo .Doctors_DoctorId 'в таблице' Встречи 'может вызвать циклы или несколько каскадных путей. Укажите ON DELETE NO ACTION или ON UPDATE NO ACTION или измените другие ограничения FOREIGN KEY. Не удалось создать ограничение или индекс. Смотрите предыдущие ошибки.

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; }
}`

В чем проблема?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...