C# Linq:如何在查询语法中编写任何查询? IEnumerable cand=(IEnumerable)总体。其中( x=>!x.Attributes.Any( y=>y.GetType()==typeof(Arbeit) ) );
我想知道我怎么能用查询语法来写上面的内容,但由于任何方法的原因,我都犯了错误。在查询语法中并没有与C# Linq:如何在查询语法中编写任何查询? IEnumerable cand=(IEnumerable)总体。其中( x=>!x.Attributes.Any( y=>y.GetType()==typeof(Arbeit) ) );,c#,linq,C#,Linq,我想知道我怎么能用查询语法来写上面的内容,但由于任何方法的原因,我都犯了错误。在查询语法中并没有与Any等价的东西。因此,您所能做的就是: IEnumerable<Gruppe> cand = (IEnumerable<Gruppe>)populations.Where( x => !x.Attributes.Any( y => y.Get
Any
等价的东西。因此,您所能做的就是:
IEnumerable<Gruppe> cand = (IEnumerable<Gruppe>)populations.Where(
x => !x.Attributes.Any(
y => y.GetType() == typeof(Arbeit)
)
);
IEnumerable cand=
人口中的人口
哪里population.Attributes.Any(y=>y.GetType()==typeof(Arbeit))
选择人群
(我假设转换为
IEnumerable
是没有必要的。如果这个假设是错误的,你需要将它添加回去。)任何都可以重构,但你仍然需要一个计数
IEnumerable<Gruppe> cand =
from population in populations
where !population.Attributes.Any(y => y.GetType() == typeof(Arbeit))
select population
使用select(cand=>IEnumerable…)您的意思是替换强制转换吗?对不起!我以为您在询问查询语法中的上述代码。你可能是指。Where(…)
部分?
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;