foreach(在新DataAccess.IncidentRepository()中的var事件.GetItems()。其中( i => (startDate == null || i.IncidentDate> = startDate) &安培;&安培; (endDate == null || i.IncidentDate< = endDate) &安培;&安培; (shiftId == null || i.ShiftId == shiftId) &安培;&安培; (processAreaId == null || i.ProcessAreaId == processAreaId) &安培;&安培; (plantId == null || i.PlantId == plantId)))
如果i.PlantId == plantId
为plantId
,我可以null
无法添加吗?
由于
答案 0 :(得分:2)
var incident in new DataAccess.IncidentRepository().GetItems().Where(
i => i.IncidentDate >= startDate
&& i.IncidentDate <= endDate
&& i.ShiftId == shiftId
&& i.ProcessAreaId == processAreaId
&& (plantId == null || i.PlantId == plantId)))
或者,您可以:
var incidents = new DataAccess.IncidentRepository().GetItems().Where(
i => i.IncidentDate >= startDate
&& i.IncidentDate <= endDate
&& i.ShiftId == shiftId
&& i.ProcessAreaId == processAreaId));
if (plantId != null)
incidents = incidents.Where(i => i.PlantId == plantId);
foreach (var incident in incidents) {
// ...
}
答案 1 :(得分:0)
var incident in new DataAccess.IncidentRepository().GetItems().Where(
i => i.IncidentDate >= startDate
&& i.IncidentDate <= endDate
&& i.ShiftId == shiftId
&& i.ProcessAreaId == processAreaId
&& object.Equals(i.PlantId, plantId)))