c# - Groupby list within the list using LINQ -
i have 2 classes:
class customer { public string name { get; set; } public string zipcode { get; set; } public list<order> orderlist { get; set; } } class order { public string ordernumber { get; set; } } using linq, want list of orders group zipcode. if zipcode "12121" has 10 customers , each has 2 orders should return me 1 zipcode list of 20 orders.
i trying not able figure out whats wrong
var orders = br.custorderlist .select(r => new { r.zipcode, r.name, r.orderlist }) .groupby(x => new { x.zipcode, x.orderlist}); any please?
this should want:
var orders = br.custorderlist .groupby(x => x.zipcode) .select(g => new { zipcode = g.key, orders = g.selectmany(x => x.orderlist) });
Comments
Post a Comment