LINQ到对象-不包含对象? [英] LINQ to Objects - Does Not Contain?

查看:56
本文介绍了LINQ到对象-不包含对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目集合,每个项目都有一个关系集合.我有一个项目可以与之建立关系的组列表.

I have a collection of Items that each have a collection of Relationships. I have a list of Groups that Items can have Relationships with.

我可以找到所有具有特定关系的项目,但是现在我想找到与我的任何组都没有关系的所有项目.

I can find all the Items that have a particular relationship but I now want to find all the Items that don't have a Relationship with any of my Groups.

通过执行以下操作,我可以找到与任何组都有关系的项目:

I can find the Items that have a relationship with any of the Groups by doing this:

Dim groupIds as List(of Integer) = (From g In cmdbGroups Select g.ID).ToList
Dim haveGroup = (From item In items _
                 Where item.Relationships.Any(Function(r) groupIds.Contains(r.TargetID)) _
                 Select item).ToList

如何找到与任何组都没有关系的所有项目?

How can I find all the items that do not have a relationship with any of the groups?

推荐答案

我不太记得VB,但是一个简单的"Not"应该可以.

I don't remember VB all that well, but a simple "Not" should work.

Dim groupIds as List(of Integer) = (From g In cmdbGroups Select g.ID).ToList
Dim haveGroup = (From item In items _
             Where Not item.Relationships.Any(Function(r) groupIds.Contains(r.TargetID)) _
             Select item).ToList

这篇关于LINQ到对象-不包含对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆