0

这是我的清单

locList.Add(New Location() With {.ID = "001", .Name = "KTYM"})
' 2 products
prdList.Add(New Product() With {.ID = "001", .Locations = locList, .Name = "Boost"})
prdList.Add(New Product() With {.ID = "003", .Locations = locList, .Name = "Pears"})


locList = New List(Of Location)
prdList = New List(Of Product)
locList.Add(New Location() With {.ID = "002", .Name = "TVM"})
' 3 products
prdList.Add(New Product() With {.ID = "002", .Locations = locList, .Name = "Horlicks"})
prdList.Add(New Product() With {.ID = "003", .Locations = locList, .Name = "Pears"})
prdList.Add(New Product() With {.ID = "004", .Locations = locList, .Name = "Colgate"})


locList = New List(Of Location)
prdList = New List(Of Product)
locList.Add(New Location() With {.ID = "003", .Name = "KNR"})
' 4 prod
prdList.Add(New Product() With {.ID = "B05", .Locations = locList, .Name = "CloseUP"})
prdList.Add(New Product() With {.ID = "003", .Locations = locList, .Name = "Pears"})
prdList.Add(New Product() With {.ID = "016", .Locations = locList, .Name = "Maggi"})
prdList.Add(New Product() With {.ID = "A07", .Locations = locList, .Name = "Dairy Milk"})

每个产品都有一个位置。我想从给定位置的列表中选择所有产品。我怎样才能实现它?我正在为 CE 设备使用 .net 3.5。谢谢你的帮助。

编辑

Dim prd = From p As Product In prdList _
                  From loc As Location In p.Locations _
                  Where loc.ID = "001" _
                  Select p

这里 prd.Count 它返回零。

4

1 回答 1

1

C# 将是.Where( p => p.Locations.Any( loc => loc.ID == LocIdYouWant ) )

我认为这可能是等效的 VB.Net:

.Where( Function(p) p.Locations.Any( Function( loc ) loc.ID = LocIdYouWant ) )

于 2013-10-03T15:14:12.340 回答