简体   繁体   English

如何选择集合列表中可用的子集合

[英]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. 我的收藏包含50种产品,每种产品都有一些位置。 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) 如何使用Linq查询此集合以获取不同的子集合(所有产品的所有Locations ,但不同。因为可以在同一位置看到2个产品)

I am using .NET 3.5 CE 我使用的是.NET 3.5 CE

Thanks in advance. 提前致谢。

Use SelectMany to get all locations and Distinct to make them distinct: 使用SelectMany获取所有位置并使用Distinct使它们区别开来:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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