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 关注
- 77 浏览
添加回答
举报