1 回答

TA貢獻1757條經驗 獲得超8個贊
你的區別是
join ev in _unitOfWork.Repository<EventLogs>().Get(e => e.Description.Contains(eventRequestModel.Description) && eventRequestModel.Severity.Contains(e.Severity.ToString()))
//^^^^^^^^^^^^^^ Here
您可以使用三元運算符來避免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()))
你的整個代碼看起來像,
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 關注
- 114 瀏覽
添加回答
舉報