使用 LINQ 获取不在父列表中的项目列表

发布于 2024-10-26 21:43:22 字数 575 浏览 2 评论 0原文

我正在 vb.net 中编写应用程序,

我有两个变量,一个包含 RoomRate 列表,另一个包含 RoomTypes 列表。

我们在 RoomRate 中将 RoomRates 和 RoomType 与 RoomTypeInfo 变量链接起来。

那么我如何找到没有定义 RoomRates 的 RoomType。

我的示例代码:

class RoomType
    property UIN as integer
    property Title as string
end class

class RoomRates
    property UIN as integer
    property RoomTypeInfo as RoomType
    property Rate as double
end Class

myRoomRateList = RoomRates.GetData() 'List of RoomRates
myRoomTypeList = RoomTypes.GetData() 'List of RoomTypes

myRoomTypesWithNoRate = ???

I am writing app in vb.net

I have two variables one with list of RoomRate and other with list of RoomTypes.

We have RoomRates and RoomTypes linked with RoomTypeInfo variable insite the RoomRate.

So how do i find the RoomTypes which donot have the RoomRates Defined.

My Sample Code:

class RoomType
    property UIN as integer
    property Title as string
end class

class RoomRates
    property UIN as integer
    property RoomTypeInfo as RoomType
    property Rate as double
end Class

myRoomRateList = RoomRates.GetData() 'List of RoomRates
myRoomTypeList = RoomTypes.GetData() 'List of RoomTypes

myRoomTypesWithNoRate = ???

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

故人爱我别走 2024-11-02 21:43:22

尝试这样的事情:

myRoomTypesWithNoRate 
    = myRoomTypeList.Where( _
          Function (rt as RoomType) return not myRoomRateList.Contains( _
              Function (rr as RoomRates) return rr.RoomTypeInfo.UIN = rt.UIN) _
          ) _
        )

注意:这没有经过测试(甚至没有编译),但它应该给出这个想法。

Try something like this:

myRoomTypesWithNoRate 
    = myRoomTypeList.Where( _
          Function (rt as RoomType) return not myRoomRateList.Contains( _
              Function (rr as RoomRates) return rr.RoomTypeInfo.UIN = rt.UIN) _
          ) _
        )

Note: this isn't tested (or even compiled), but it should give the idea.

尘世孤行 2024-11-02 21:43:22

未测试(我不在家)

Dim myRoomTypesWithNoRate = myRoomTypeList.Where(Function(c) myRoomTypeList.Where(Function(f) f.UIN = c.UIN).Count = 0)

这应该返回具有 myRoomTypeList 中不存在的 UIN 的所有 RoomType

Not Tested (I'm not at home)

Dim myRoomTypesWithNoRate = myRoomTypeList.Where(Function(c) myRoomTypeList.Where(Function(f) f.UIN = c.UIN).Count = 0)

This should return all the RoomTypes that has an UIN that is not present in myRoomTypeList

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文