我有身体检查的模型
public class PatientMedicalExam
{
public int Id {get; set;}
public int PatientId {get; set;}
public int MedicalExamId {get; set;}
public DateTime Date {get; set;} // realization date
public DateTime NextDate {get; set;}
}
无论何时添加考试,考试都会有下一个日期(NextDate
)
我想根据输入的日期(NextDate
)返回下一次检查,如果已经存在(Date
),则该检查不存在
我尝试过:
var query = db.PatientMedicalExams.AsQueryable()
.Where(x =>
x.NextDate != null &&
DbFunctions.TruncateTime(x.NextDate) >= model.Start &&
DbFunctions.TruncateTime(x.NextDate) <= model.End &&
DbFunctions.TruncateTime(x.Date) <= model.End &&
DbFunctions.TruncateTime(x.Date) >= model.End);
[编辑]样本数据
Start
参数= 01/01/2019 End
参数= 31/01/2019
ID, PATIENTID, MEDICALEXAMID, DATE, NEXTDATE
1 1 1 01/01/2018 01/01/2019 //this next date for medical examination
2 1 2 01/01/2018 01/01/2019 //expired
3 1 1 12/31/2018 12/31/2019 //this medical examination has been realized before expiration
然后patientid
1到期的唯一医学检查是medicalexamId
2