【发布时间】:2017-10-20 22:12:36
【问题描述】:
我有 3 张桌子
约会、医生和 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; }
}
三等舱
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; }
}
我需要从前面的选择中获取医生的 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”的定义,并且找不到接受“ICollection”类型的第一个参数的扩展方法“Doctor_id”(您是否缺少 using 指令或程序集引用?) RS_Main C:\ Users\nemes\Source\Repos\RIS_Project_New\RS_Main\Controllers\CalendarController.cs 105 活动
非常感谢您的帮助!
【问题讨论】:
-
你不会写是什么意思? IntelliSense 不给你选项或者你输入
Doctor_id并给你编译错误? -
我更新了我的问题@FortyTwo
-
为什么你的模型类是部分类?如果您在
Appointments_to_Doctors表中查看您的数据库,您是否有一个名为Doctor_id的列?链接表具有可为空的外键也有点奇怪 - 这似乎是一个错误 -
看来你的问题是你有一个 iccollection
并且你的属性存在于一个实例上。试试:e=> e.Appointments_to_Doctors.Any(atd => atd.Doctor_id == {yourid}) 这对你有用吗? -
类是通过 EF 从 DB 生成的,是的,我在 DB@peggy 中有这个专栏
标签: c# asp.net asp.net-mvc