c# - Dynamic Grouping Using LINQ -
please have @ below example. grouping clause has dynamic. can please guide me how can achieved. i.e. row { r.portfolio, r.datatype } has contructed dynamically.
not sure how can tweek solution given @ blog http://jonahacquah.blogspot.com/2012/02/groupby-multiple-columns-using-dynamic.html
public class decisionsupportdata { public string portfolio { get; set; } public string bucketname { get; set; } public string datatype { get; set; } public string childportfolio { get; set; } } public void populatedata() { list<decisionsupportdata> lstalldecsupp = decisionsupportdatabindingsource.datasource list<decisionsupportdata>; list<decisionsupportdata> lstrmgamt = (from r in lstalldecsupp.asenumerable() r.datatype == "p" grouping r new { r.portfolio, r.datatype } gg select new decisionsupportdata { datatype = gg.key.datatype, portfolio = gg.key.portfolio, }).tolist(); }
thx help.
the dynamiclinq library appear solve issue, mentioned in scott gu's original blog. utilize groupby extension method string value.
or dig expressionparser class , see it's doing.
c# linq dynamic group
No comments:
Post a Comment