0
Public Class Product
public  Name As String
public  ID as String
public  ShelfList as List(of Shelf)
End Class 

Public Class Shelf
public  Name As String
public  ID as String
public  Row as List(of Row)
End Class

Public Class Row
public  Name As String
public  ID as String
End Class

以上是我的课。假设可以在不同的货架和不同的行中找到产品。此外,一排可以容纳多个产品。

数据将与此类似。

List(of Products) -> List(of Shelf) -> List(of Rows)

以下是类似的数据

Boost ->  Shelf 1 -> Row 1,Row 2 
          Shelf 2 -> Row 2

Horlicks ->Shelf 1-> Row 1

Complain ->Shelf 2-> Row 2,Row 3

Colgate -> Shelf 2- Row 3

因此,我需要从上面的产品列表中生成摘要。(行名和每行项目数)

   Shelf 1 Row 1 - 2 (Boost and horlicks)
   Shelf 1 Row 2 - 1 (Boost)
   Shelf 2 Row 1 - 1 (Horlicks)
   Shelf 2 Row 2 - 2 (Complain and Boost)
   Shelf 2 Row 3 - 1 (Colgate)

笔记 :

  1. Shelf 1 Row 1 是第一个货架第一行的名称。

  2. 无需在括号中显示项目名称。现在只是为了理解而展示。

如何使用 LINQ 实现这一点。我正在使用 VB.NET 并以 CE 3.5 为目标。C# 建议也受到赞赏。提前致谢。

4

2 回答 2

0

我认为你必须改变你的数据结构

我会这样做

货架列表 --> 行列表 --> 产品列表

为什么产品会跟踪该行?它是包含不同产品的行。

每个架子

选择货架号-->行号-->产品名称

于 2013-09-27T07:58:02.463 回答
0

例如,您可以嵌套 LINQ 查询(对不起,我是 C-sharp man);

var a = from t1 in Products
        select new 
        {
             Name = t1.Name,
             Summary = String.Join(", ",(from t2 in t1.ShelfList
                        select t2.Name))
        };

应该这样做,尽管我忽略了第三层。

于 2013-09-27T10:46:58.943 回答