c# - Join + Group + Aggregate in LINQ -
i have following query, put datagrid:
var balanceperaccount = bal in data.balancedetails join acc in data.userpaymentdetails on bal.username equals acc.username bal.paymentid == 0 group bal bal.username g g.sum(p => p.rebatebeforeservice) >= 20 select new { username = g.key, amount = g.sum(p => p.rebatebeforeservice), }; dgpaymentspending.datasource = balanceperaccount; dgpaymentspending.databind(); what add inside acc in select. example add paymentprovider = acc.paymentprovider. tried flipping every way think of, including getting first() group , trying access there, can't seem find way access it. might missing simple, have been looking around google time , can't seem find comparable example. have idea?
extend grouping source using anonymous type: new { bal, acc } , use first
var balanceperaccount = bal in data.balancedetails join acc in data.userpaymentdetails on bal.username equals acc.username bal.paymentid == 0 group new { bal, acc } bal.username g g.sum(p => p.bal.rebatebeforeservice) >= 20 select new { username = g.key, paymentprovider = g.firstordefault().acc.paymentprovider, amount = g.sum(p => p.bal.rebatebeforeservice), };
Comments
Post a Comment