You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

LINQ查询中筛选IEnumerable<string>非空记录报错,如何解决?

Solution for LINQ to Entities Filter Error with IEnumerable Comparison

The error you're seeing happens because LINQ to Entities can't translate comparisons of IEnumerable<T> types (like your ModifiedAmounts property) to SQL. Additionally, the ModifiedAmounts sequence will never actually be null—it will be an empty collection if there are no matching Expenditure records for a scheme.

To fix this, you need to adjust your filter to check the contents of the sequence instead of comparing it to null. Here are two common solutions based on what you're trying to achieve:

1. Filter for records with at least one ModifiedAmount entry

If you want to keep only schemes that have at least one associated Expenditure (so ModifiedAmounts isn't empty), use the Any() method to check if the sequence contains elements:

if (rbList2.SelectedIndex == 6)
{
    result = result.Where(a => a.ModifiedAmounts.Any());
}

2. Filter for records with at least one non-null ModifiedAmount

If you specifically want schemes where at least one ModifiedAmounts value in the group is not null, add a predicate to the Any() method:

if (rbList2.SelectedIndex == 6)
{
    result = result.Where(a => a.ModifiedAmounts.Any(ma => ma != null));
}

Both of these approaches are translatable to SQL by LINQ to Entities, so they won't throw the error you encountered. Choose the one that matches your actual filtering requirement.

内容的提问来源于stack exchange,提问作者AKA

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.29 09:03:51