对于以下查询:
var result = from sch in schemeDashboard
join exp in Expenditure on sch.schemeId equals exp.SchemeCode
into SchExpGroup
where sch.SectorDepartmentId == selectedDepartmentId &&
sch.YearCode == StateManager.CurrentYear
orderby sch.ADPId
select new
{
ModifiedAmounts = SchExpGroup.Select(a => a.ModifiedAmounts),
ProjectName = sch.schemeName,
ADPNo = sch.ADPId,
Allocation = sch.CurrentAllocation,
Expenditures = from expend in SchExpGroup
where expend.YearCode == StateManager.CurrentYear &&
expend.DepartmentId == selectedDepartmentId &&
InvStatus.Contains(expend.Status)
orderby expend.ADPId
group expend by expend.InvoiceId
};
我想在条件上过滤上述查询,以便结果只提供那些" ModifiedAmounts"不是空的。我尝试过如下:
if (rbList2.SelectedIndex == 6)
{
result = result.Where(a => a.ModifiedAmounts != null));
}
但这会产生错误:
无法比较类型的元素 ' System.Collections.Generic.IEnumerable`1&#39 ;.只有原始类型, 支持枚举类型和实体类型。
任何建议,因为我丢失了如何重新定义过滤后的查询。
答案 0 :(得分:1)
我认为问题是ModifiedAmounts永远不会为null。选择将返回一个空列表。除非SchExpGroup为null,否则您将获得空引用异常。
尝试将代码更改为
result = result.Where(a => a.ModifiedAmounts.Any());
答案 1 :(得分:0)
if (rbList2.SelectedIndex == 6)
{
result = result.Where(a => a.!ModifiedAmounts.Any());
}