我是新来的。我的问题是:
List<string> positions = new List<string> { "x1", "x2", "x3 };
var results = _context_WObjects.AsQueryAble();
结果返回具有以上类的 IQueryAble 列表的列表:
class objectclass {
public string position {get; set; }
public string test {get; set; }
/*... other properties....*/
}
我如何找到所有具有(不包含)职位列表之一的职位的项目?
我试过:
results = results.Where(n1 => positions.Any(n2 => n2 == n1.position));
但它不起作用!!
异常错误是:
“除了 Contains 运算符外,本地序列不能用于查询运算符的 LINQ to SQL 实现。”
我从意大利语翻译而来。
谢谢 非常 克里斯
最佳答案
错误信息很清楚。您不能使用 Any
像这样的本地收藏 List<string>
但你可以使用 Contains
.你还想要 !Contains
:
results = results.Where(n1 => !positions.Contains(n1.position));
关于c# - 在对象列表中查找所有具有属性的项目存在于其他列表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52966907/