預約,醫生和Appointment_to_Doctor
這裏是約會類
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public Appointment()
{
this.Patient_to_appointment = new HashSet<Patient_to_appointment>();
this.Appointments_to_Doctors = new HashSet<Appointments_to_Doctors>();
}
[Key]
public int Id { get; set; }
public string Start_appointment { get; set; }
public string End_appointment { get; set; }
public string Title { get; set; }
public string Type_of_appointment { get; set; }
[ForeignKey("Patient")]
public Nullable<int> Patient_id { get; set; }
public string Kasse { get; set; }
public Nullable<System.DateTime> Date { get; set; }
public virtual Patient Patient { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<Patient_to_appointment> Patient_to_appointment { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<Appointments_to_Doctors> Appointments_to_Doctors { get; set; }
}
這裏是醫生類
public partial class Doctor
{
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2214:DoNotCallOverridableMethodsInConstructors")]
public Doctor()
{
this.Appointments_to_Doctors = new HashSet<Appointments_to_Doctors>();
}
[Key]
public int Id { get; set; }
public string Organization { get; set; }
public string Title { get; set; }
public string Sex { get; set; }
public string First_Name { get; set; }
public string Last_Name { get; set; }
public string C_O { get; set; }
public string Street { get; set; }
public string Index { get; set; }
public string City { get; set; }
public string Country { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
public string Fax { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<Appointments_to_Doctors> Appointments_to_Doctors { get; set; }
}
and third class
public partial class Appointments_to_Doctors
{
[Key]
public int Id { get; set; }
public Nullable<int> Doctor_id { get; set; }
public Nullable<int> Appointment_id { get; set; }
[ForeignKey("Appointment_id")]
public virtual Appointment Appointment { get; set; }
[ForeignKey("Doctor_id")]
public virtual Doctor Doctor { get; set; }
}
我需要從前面的select中獲取醫生的id,將它傳遞給後端並進行選擇。
所以在後端我有這個代碼。
public JsonResult GetEvents()
{
using (var ctx = new ApplicationDbContext())
{
var eventList = ctx.Appointments.Where(e=> e.Appointments_to_Doctors.).Select(e => new
{
id = e.Id,
title = e.Title,
start = e.Start_appointment.ToString(),
end = e.End_appointment.ToString(),
allDay = false
});
var rows = eventList.ToArray();
return Json(rows, JsonRequestBehavior.AllowGet);
}
}
但這裏ctx.Appointments.Where(e=> e.Appointments_to_Doctors.)
點後,我不能寫Doctor_id
。爲什麼?
我有這個
嚴重性代碼說明項目文件的線路抑制狀態 錯誤CS1061「ICollection的」不包含「Doctor_id」的定義,並沒有擴展方法「Doctor_id」接受一個類型的第一個參數「 ICollection的」可以找到(是否缺少using指令或程序集引用?)RS_Main C:\用戶\ nemes \來源\回購\ RIS_Project_New \ RS_Main \ \控制器105 CalendarController.cs主動
感謝的求助非常!
你是什麼意思,你不能寫?智能感知不會給你選擇,或者你輸入'Doctor_id'並給你編譯錯誤? – FortyTwo
我更新了我的問題@FortyTwo –
爲什麼你的模型類部分類?如果你在'Appointments_to_Doctors'表中查看你的數據庫,你有一個名爲'Doctor_id'的列嗎?連接表有可空的外鍵也有點奇怪 - 這看起來像是一個錯誤 – GregH