【发布时间】:2022-01-01 09:58:54
【问题描述】:
我正在创建一个简单的患者应用程序。 1-1 患者与病史记录的关系。当应用程序启动时,会显示患者。选择一个患者并单击按钮时,应显示该患者的病史。
我的问题是显示所有病史,而不是显示特定患者。
private void PopulateGrid()
{
var records = _db.GeneralMedicalHistories.Select(q => new
{
PatientNumber = q.GeneralMedicalHistoryID,
MaritalStatus = q.MartialStatus,
Education = q.Education,
BloodType = q.BloodType,
Pregenancies = q.Pregnancies,
Tobacco = q.Tobacco,
Alcohol = q.Alcohol,
Drug = q.Drug,
MedicalHistoryNotes = q.MedicalHistoryNotes,
}).ToList();
gvDemographics.DataSource = records;
gvDemographics.Columns["PatientNumber"].HeaderText = "Patient#";
gvDemographics.Columns["MaritalStatus"].HeaderText = "Marital Status";
gvDemographics.Columns["BloodType"].HeaderText = "Blood Type";
gvDemographics.Columns["MedicalHistoryNotes"].HeaderText = "Medical History Notes";
//Hide the column for ID. Changed from the hard coded column value to the name,
// to make it more dynamic.
gvDemographics.Columns["PatientNumber"].Visible = true;
}
实现 .Where() 后的新代码。 C_PatientID 是病史表中的外键,与患者表中的主键匹配
var record = _db.GeneralMedicalHistories.Where(q => q.C_PatientID == q.Patient.PatientID).Select(q => new
{
PatientNumber = q.GeneralMedicalHistoryID,
MaritalStatus = q.MartialStatus,
Education = q.Education,
BloodType = q.BloodType,
Pregenancies = q.Pregnancies,
Tobacco = q.Tobacco,
Alcohol = q.Alcohol,
Drug = q.Drug,
MedicalHistoryNotes = q.MedicalHistoryNotes,
}).ToList();
【问题讨论】: