c# - Grouping troubles -
hi having difficulties group these data has no aggregate function. have following data in 2 tables , join both paymentid , display 1 row of record.

question:
how display final result in 1 row groupby coursepaidformonthyear.
data payment.*, tutorcoursecommissions.* , coursepaidformonthyear column in same row displaying (september, october, november)
example:
referenceid| tutorid| coursepaidformonthyear | 1 | 1019 | september, october, november or 9,10,11| my work:
var result = u in db.users join p in db.payments on u.id equals p.userid join tt in db.tutorcoursecommissions on p.id equals tt.paymentid gtt tt in gtt.defaultifempty() u.id == user.id groupby tt.coursepaidformonthyear ?? select new { u, p, tt }; foreach (var r in result) { payment payment = new payment(); payment.monthtopay = (r.tt == null) ? null : common.getmonthname(r.tt.coursepaidformonthyear.month, true); payment.amount = r.p.amount; output.add(payment); } return output;
what need group months user , payment, , perform aggregation on grouped months. in case used string.join() combine distinct months coming commission.
this give results along lines of { user = "john doe", payment = ..., months = "january, february" }
var result = u in db.users u.userid == user.id join p in db.payments on u.id equals p.userid join comm in db.tutorcoursecommissions on p.id equals comm.paymentid group common.getmonthname(comm.coursepaidformonthyear,true) new { user = u, payment = p } g select new { user = g.key.user, payment = g.key.payment, //...select out other properties here... months = string.join(", ", g.distinct()) };
Comments
Post a Comment