c# - How to get linq to transform data from one form to another -
say have objects:
public class paymentheader { public payee payee { get; set; } public list<payment> payments { get; set; } } public class payment { public int amount { get; set; } } public class payee { public string name { get; set; } }
so paymentheader has payee , list of payments.
what wanting transform data different format.
so after list<payee>
each payee has list<paymentheader>
i started going:
var data = paymentheaders.groupby(x => x.payee)
so here trying achieve getting payees associated paymentheaders. think right starting point don't know how further. think need create anonymous type unsure how put payees list , add list of paymentheaders each payee.
can me this.
you need build type hold this, or use anonymous type:
var data = paymentheaders.groupby(x => x.payee) .select(g => new { payee = g.key, headers = g.tolist() }) .tolist(); foreach(var d in data) { console.writeline("payee {0} has {1} headers", d.payee, d.headers.count); }
Comments
Post a Comment