3 回答
TA贡献2016条经验 获得超9个赞
查询语法中没有与 Any 等效的内容。所以你能做的最好的事情是:
IEnumerable<Gruppe> cand =
from population in populations
where !population.Attributes.Any(y => y.GetType() == typeof(Arbeit))
select population
(我假设没有必要强制转换为 IEnumerable<Gruppe>。如果该假设错误,您需要将其添加回来。)
TA贡献1805条经验 获得超10个赞
我喜欢斯维克的回答。
另一种说法是这样的:
IEnumerable<Gruppe> cand =
from population in populations
where ( from attribute in population.Attributes
where attribute.GetType() == typeof(Arbeit)
select true).Any() == false
select population
TA贡献1809条经验 获得超8个赞
Any 可以重构,但您仍然需要 Count。
var cand = from population in populations
let attributeCount = population.Attributes.Count
let validAttributeCount = (
from attribute in population.Attributes
where attribute.GetType() != typeof(Arbeit)
select attribute
).Count()
where attributeCount == validAttributeCount
select population;
- 3 回答
- 0 关注
- 165 浏览
添加回答
举报