How to combine 2 LINQ into one

I am trying to populate a treeview control with some information and for this I am using two separate LINQ statements like this:

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

      

Is there a way to combine A and B into one query? Any help please ...

0


a source to share


1 answer


Well, really B is one request. Remember that what is returned from the Linq statement is IQueryable, not the actual result. This means that B is concatenating its own expressions with the expressions of A, but the search is not performed until you list B. So B is really just one query.



+3


a source







All Articles