Vb.net 使用LINQ获取不在父列表中的项列表

Vb.net 使用LINQ获取不在父列表中的项列表,vb.net,linq,list,Vb.net,Linq,List,我正在用vb.net编写应用程序 我有两个变量,一个是RoomRate列表,另一个是RoomTypes列表 我们在RoomRate中有RoomTypeInfo变量链接的RoomRates和RoomTypes 那么我如何找到没有定义房价的房间类型呢 我的示例代码: class RoomType property UIN as integer property Title as string end class class RoomRates property UIN as

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

我有两个变量,一个是RoomRate列表,另一个是RoomTypes列表

我们在RoomRate中有RoomTypeInfo变量链接的RoomRates和RoomTypes

那么我如何找到没有定义房价的房间类型呢

我的示例代码:

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 = ???

试着这样做:

myRoomTypesWithNoRate 
    = myRoomTypeList.Where( _
          Function (rt as RoomType) return not myRoomRateList.Contains( _
              Function (rr as RoomRates) return rr.RoomTypeInfo.UIN = rt.UIN) _
          ) _
        )
注意:这没有经过测试(甚至没有经过编译),但它应该给出一个想法。

没有测试(我不在家)

这将返回所有具有不在myRoomTypeList中的UIN的RoomTypes

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