简体   繁体   中英

How to select a sub collection available in a list of collection

The following is my class structure

   public class ProductInfo
         Dim productName As string 
      Dim productCode As string 
      Dim Locations As List(of String)
   End Class

Getting product List

Dim listProd As List(of ProductInfo)= entityProvider.GetProducts();

My collection contains 50 products and each product will have some number of locations. How can I query this collection using Linq to get distinct sub collection (all Locations for all the product, but distinct. Because 2 product can be seen in same location)

I am using .NET 3.5 CE

Thanks in advance.

Use SelectMany to get all locations and Distinct to make them distinct:

Dim distinctLocations = entityProvider.GetProducts().
    SelectMany(Function(p) p.Locations).
    Distinct()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM