1 回答

TA貢獻(xiàn)1757條經(jīng)驗(yàn) 獲得超8個(gè)贊
你的區(qū)別是
join ev in _unitOfWork.Repository<EventLogs>().Get(e => e.Description.Contains(eventRequestModel.Description) && eventRequestModel.Severity.Contains(e.Severity.ToString()))
//^^^^^^^^^^^^^^ Here
您可以使用三元運(yùn)算符來(lái)避免if (!string.IsNullOrWhiteSpace(eventRequestModel.Description))檢查
喜歡,
join ev in _unitOfWork.Repository<EventLogs>()
.Get(e =>
string.IsNullOrWhiteSpace(eventRequestModel.Description) ? true : e.Description.Contains(eventRequestModel.Description)
&& eventRequestModel.Severity.Contains(e.Severity.ToString()))
你的整個(gè)代碼看起來(lái)像,
if (eventRequestModel.Severity.Count > 0)
{
eventsModelList = (from job in _unitOfWork.Repository<Jobs>().Get(j => eventRequestModel.SiteIds.Contains(j.JobId.ToString())).Result
join ev in _unitOfWork.Repository<EventLogs>().Get(e => string.IsNullOrWhiteSpace(eventRequestModel.Description) ? true : e.Description.Contains(eventRequestModel.Description)
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Your answer is here
&& eventRequestModel.Severity.Contains(e.Severity.ToString())).Result on job.JobId equals ev.JobId
join pnl in _unitOfWork.Repository<Panels>().Get(el => eventRequestModel.SiteIds.Contains(el.JobId.ToString())).Result on ev.PanelId equals pnl.PanelId
orderby ev.TimeStamp descending, ev.EventId descending
select new EventsModel
{
//Your code
}).Take(numOfItems).ToList();
}
else
{
eventsModelList = (from job in _unitOfWork.Repository<Jobs>().Get(j => eventRequestModel.SiteIds.Contains(j.JobId.ToString())).Result
join ev in _unitOfWork.Repository<EventLogs>().Get(e => string.IsNullOrWhiteSpace(eventRequestModel.Description) ? true : e.Description.Contains(eventRequestModel.Description)
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Your answer is here
&& eventRequestModel.Severity.Contains(e.Severity.ToString())).Result on job.JobId equals ev.JobId
join pnl in _unitOfWork.Repository<Panels>().Get(el => eventRequestModel.SiteIds.Contains(el.JobId.ToString())).Result on ev.PanelId equals pnl.PanelId
orderby ev.TimeStamp descending, ev.EventId descending
select new EventsModel
{
//Your code
}).Take(numOfItems).ToList();
}
}
- 1 回答
- 0 關(guān)注
- 121 瀏覽
添加回答
舉報(bào)