如何将2个LINQ合二为一

时间:2009-05-17 21:01:00

标签: linq

我正在尝试用一些信息填充树视图控件,为此我使用了两个单独的LINQ语句,如下所示;

Dim a = From i In CustomerTable _
        Group By ShipToCustName = i.Item(6), BillToCustName = i.Item(4) Into Details = Group, Count() _
        Order By ShipToCustName


Dim b = From x In a _
        Group By ShipToName = x.ShipToCustName Into Group, Count() _
        Order By ShipToName

For Each item In b
        Console.WriteLine("Shitp To Location: " + item.ShipToName)
        For Each x In item.Group
            Console.WriteLine("...BillTo:" + x.BillToCustName)
            For Each ticket In x.Details
                Console.WriteLine("......TicketNum" + ticket.Item(0).ToString)

            Next
        Next
Next

有没有办法将A和B组合成一个查询?任何帮助请...

1 个答案:

答案 0 :(得分:3)

嗯,真的B是一个单一的查询。请记住,从Linq语句返回的内容是IQueryable,而不是实际结果。这意味着B将自己的表达式与A的表达式结合起来,但是在枚举B之前不会执行检索。所以B实际上只是一个查询。