score:1

Accepted answer

something like this :

        var p1 = new product(){count=15, name="a", vendor = 1, year = 1990};
        var p2 = new product() { count = 20, name = "a", vendor = 2, year = 1990 };
        var p3 = new product() { count = 5, name = "a", vendor = 4, year = 1998 };
        var p4 = new product() { count = 15, name = "b", vendor = 1, year = 1995 };
        var p5 = new product() { count = 2, name = "b", vendor = 1, year = 1995 };

        var inputlist = new[] {p1, p2, p3, p4, p5};

        var newstructure = inputlist
            .groupby( p => new { p.name, p.year } )
            .select( g => new { g.key.name, g.key.year, vendorcount = g.todictionary(p => p.vendor, p => p.count) }
          );

although i don't think you can use vendor as a dictionary key, because they are not unique as it stands

score:2

use this if the combination of (name, year, vendor) is unique:

inputlist.groupby(x => new { x.name, x.year })
         .select(x => new
                      {
                          productname = x.key.name,
                          originyear = x.key.year, 
                          vendor_count = x.todictionary(y => y.vendor
                                                        y => y.count)
                      })
         .orderby(x => x.productname).thenby(x => x.originyear);

use this if it isn't unique:

inputlist.groupby(x => new { x.name, x.year })
         .select(x => new
                      {
                          productname = x.key.name,
                          originyear = x.key.year, 
                          vendor_count = x.groupby(y => y.vendor)
                                          .todictionary(y => y.key,
                                                        y => y.sum(z => z.count))
                      })
         .orderby(x => x.productname).thenby(x => x.originyear);

Related Query

More Query from same tag