[英]How to retrieve data from multiple tables using EF 5 linq method
我面临一个问题,如下所述。
我有四张桌子
PateintTable
PatientRecordTable(FK=PatientID)
RecordMedicineTable(FK=MedicineID,RecordID)
MedicineTable
我想根据患者的 PatientID 以及患者数据获取特定的患者数据,我想获取他的病历(PatientRecordTable)以及与他的每个记录相关的药物。
我尝试了很多技巧,但当我尝试获取药物时会出现例外情况。
lstPrescribedMedicines.Items.Clear();
foreach (var item in result.RecordsMedicines)
{
lstPrescribedMedicines.Items.Add(item.Medicine.MedName);
}
我正在实施using(context=new mss-context())
。 这是我的查询:
var pateintRecords = context
.PateintRecords
.Include(p => p.Patient)
.Include(m=>m.RecordsMedicines)
.Where(x => x.PatientID == pateintID).ToList();// as IQueryable;
与孩子的孩子一起工作时,您必须包括他们:
var pateintRecords = context
.PateintRecords
.Include(p => p.Patient)
.Include(m=>m.RecordsMedicines)
.Include(m=>m.RecordsMedicines.Select(i => i.Items))
.Where(x => x.PatientID == pateintID).ToList();// as IQueryable;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.