0
此語句使用我正努力擺脫一個foreach:如何才能做到這一點有一個QueryOver聲明
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
語句來做到這一點?
有什麼建議嗎?
'的.List()選擇ToList();'是多餘的。 '.List ();'就夠了 –
Firo