使用子列表中的項目這是我的名單.NET選擇列表中的
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它返回零。
你做出什麼樣的努力? –
我試過很多使用LINQ的組合,但它拋出空引用 :(讓我更新 – kbvishnu
請出示該代碼。 –