1

I've a structure collection like this:

Jet     Owner   Item    Comp
AAAA    AAAA    101     2210
AAAA    AAAA    202     2220
AAAA    AAAA    301     5550
AAAA    AAAA    301     5560
AAAA    2210    101     6789
AAAA    2220    202     ABABA
AAAA    5550    301     XXXX0
AAAA    5550    301     XXXX1
AAAA    5560    301     YYYY0
AAAA    5560    301     6612
AAAA    6789    101     ZZZZZ.0
AAAA    6789    101     ZZZZZ.1
AAAA    6789    101     ZZZZZ.2
AAAA    6789    101     ZZZZZ.3
AAAA    ABABA   202     TTTTT.0
AAAA    ABABA   202     TTTTT.1
AAAA    ABABA   202     TTTTT.2
AAAA    6612    301     ZZZZZ.0
AAAA    6612    301     ZZZZZ.1
AAAA    6612    301     ZZZZZ.2
AAAA    6612    301     ZZZZZ.3
AAAB    ...     ...     .....

I need to order it for have a result like this:

Jet     Owner   Item     Comp
AAAA    AAAA    101      2210
AAAA    2210    101      6789
AAAA    6789    101      ZZZZZ.0
AAAA    6789    101      ZZZZZ.1
AAAA    6789    101      ZZZZZ.2
AAAA    6789    101      ZZZZZ.3
AAAA    AAAA    202      2220
AAAA    2220    202      ABABA
AAAA    ABABA   202      TTTTT.0
AAAA    ABABA   202      TTTTT.1
AAAA    ABABA   202      TTTTT.2
AAAA    AAAA    301      5550
AAAA    5550    301      XXXX0
AAAA    5550    301      XXXX1
AAAA    AAAA    301      5560
AAAA    5560    301      YYYY0
AAAA    5560    301      6612
AAAA    6612    301      ZZZZZ.0
AAAA    6612    301      ZZZZZ.1
AAAA    6612    301      ZZZZZ.2
AAAA    6612    301      ZZZZZ.3
AAAB    ...       ...      .....

I want to order by Jet, then where in the comp I find some there's in the Owner, put in the lines after the main owner of the relative component, then order by owner and in the last order by item. I've make the result with a C# linq query, but I need to have the same resul in a VB.NET linq query. The C# Linq query is:

    var orderedData =(from d in collection
        group d by d.Jet into g
        orderby g.Key
        from d in g
        select new[] {d}.Union(g.Where(c => c.Owner == d.Comp)) into withChildren
        from wc in withChildren
        orderby wc.Item
        select wc).Distinct();

I've tried with this in VB.NET but dosn't work:

Dim orderedData = (From d In collection 
              Group d By d.Jet Into Group 
              Order By Group 
              From d In Group 
              Select New withChildren With {d}.Union(gr.Where(Function(c) c.Owner = d.Comp))) 
                          from wc in withChildren
                          Order By wc.pos 
                          Select wc).Distinct
                          from wc in withChildren
                          Order By wc.pos 
                          Select wc).Distinct
4

1 回答 1

0

试试看:

Dim orderedData = (From withChildren In From g In From d In collectionGroup d By d.JetOrder By g.KeyFrom d In gNew () {d}.Union(g.Where(Function(c) c.Owner = d.Comp))From wc In withChildrenOrder By wc.Itemwc).Distinct()

于 2012-04-19T11:30:08.730 回答