开发者

Getting List of Items not in Parent List using LINQ

开发者 https://www.devze.com 2023-02-20 10:05 出处:网络
I am writing app in vb.net I have two variables 开发者_JAVA技巧one with list of RoomRate and other with list of RoomTypes.

I am writing app in vb.net

I have two variables 开发者_JAVA技巧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 = ???


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消