Linq multi level grouping -
i trying implement multi level grouping in linq
in sql that.
select varid, variable, ut , (case when resultat >= 0 sum(resultat) else 0) positive, (case when resultat < 0 sum(resultat) else 0) negatif (select varid, variable, ut , valeur, sum( resultat ) indicrow group varid, variable, ut , valeur) group varid, variable, ut
i have created in linq can't find way group on result of group by
var chartline = indicrow in indic_dt.asenumerable() //where seltradeid.contains(indicrow.field<int>("tradenum")) group indicrow new { gpvariable = indicrow.field<string>("variable"), gput = indicrow.field<string>("ut"), gpvarid = indicrow.field<int>("varid"), gpvalue = indicrow.field<double>("valeur") } rdval select new { varid = rdval.key.gpvarid, variable = rdval.key.gpvariable, ut = rdval.key.gput, valeur = rdval.key.gpvalue, resultat = rdval.sum(indicrow => indicrow.field<double>("resultat_euronet")) };
the final goal obtain 5 columns datatable (varid, variable, ut, positive, negative)
the general pattern fro two-level grouping is
from t in mains group t t.groupproperty1 maingroup select new { maingroup.key, maincount = maingroup.count(), subgroups = mg in maingroup group mg mg.groupproperty2 subgroup select new { subgroup.key, subcount = subgroup.count() } }
so main grouping varid, variable, ut
, sub grouping valeur
, because sub group contains items of 1 main group.
Comments
Post a Comment