预约,医生和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