我怎么能做到这一点与一个QueryOver语句
本文关键字:一个 QueryOver 语句 怎么能 这一点 | 更新日期: 2023-09-27 18:15:56
这个语句正在使用一个foreach,我试图摆脱:
CBTAppointmentDto app = null;
ModifyAppointmentRequest alias = null;
Domain.PearsonVue.TestCenter center = null;
Exam exam = null;
var result = Session.QueryOver(() => alias)
.Where(x => x.Candidate.Id == candidateId)
.Where(x => x.EventType == "ApptCreated")
.JoinAlias(x => x.Exams, () => exam)
.JoinAlias(() => alias.TestCenter, () => center)
.SelectList(list => list
.Select(() => exam.ExamName).WithAlias(() => app.TestName)
.Select(() => exam.ExamSeriesCode)
.WithAlias(() => app.ExamSeriesCode)
.Select(() => alias.AppointmentStartTime)
.WithAlias(() => app.TestDate)
.Select(() => center.TestCenterName)
.WithAlias(() => app.TestCenterName))
.TransformUsing(Transformers.AliasToBean<CBTAppointmentDto>())
.List<CBTAppointmentDto>().ToList();
foreach (var cbtAppointmentDto in result)
{
var session = Session.QueryOver<TestSession>()
.Where(x => x.SessionName == cbtAppointmentDto.ExamSeriesCode)
.SingleOrDefault();
if (session == null) continue;
cbtAppointmentDto.TestStartDate = session.TestsStartDate;
cbtAppointmentDto.TestEndDate = session.TestsEndDate;
}
return result;
是否有一种方法可以只使用QueryOver
语句?
有什么建议吗
使用ToFutureValue进行批量选择
var sessions = results.Select(cbtAppointmentDto => Session.QueryOver<TestSession>()
.Where(x => x.SessionName == cbtAppointmentDto.ExamSeriesCode)
.FutureValue()).ToOList();
for (int i = 0; i < sessions.Count; i++)
{
var session = sessions[i].Value;
if (session != null)
{
results[i].TestStartDate = session.TestsStartDate;
results[i].TestEndDate = session.TestsEndDate;
}
}