Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用Linq获取列表中项目的摘要_C#_.net_Vb.net_Linq - Fatal编程技术网

C# 如何使用Linq获取列表中项目的摘要

C# 如何使用Linq获取列表中项目的摘要,c#,.net,vb.net,linq,C#,.net,Vb.net,Linq,以上是我的课程。 假设一个产品可以在不同的货架和不同的行中找到。 此外,一行可以容纳多个产品 数据将与此类似 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

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

数据将与此类似

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)
因此,从上面的产品列表中,我需要生成摘要。(行名称和每行中的项目数)

注:

  • Shelf 1 Row 1是第一个工具架的第一行的名称

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

  • 如何使用LINQ实现这一点。
    我正在使用VB.NET,目标是CE3.5。C#也感谢您的建议。提前谢谢。

    我认为您必须更改数据结构

    我会这样做

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

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

    每个架子


    选择Shelf number-->Row number-->Product name

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


    虽然我忽略了第三层,但这样的事情应该做

    但根据设计,这是不可能的。
    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)
    
    var a = from t1 in Products
            select new 
            {
                 Name = t1.Name,
                 Summary = String.Join(", ",(from t2 in t1.ShelfList
                            select t2.Name))
            };