c# - Get parameters outside of Grouping Linq -
i need field's out of group using linq example, code:
(from paymenttypes in paymenttypes_datatable.asenumerable() join cashtransactions in cashtransactions_datatable.asenumerable() on paymenttypes.field<int32>("cashpaymenttype_id") equals cashtransactions.field<int32>("cashpaymenttype_id") joinedcashtransactions cashtransactions in joinedcashtransactions.defaultifempty() group cashtransactions paymenttypes.field<int32>("cashpaymenttype_id") grouppaymenttypes select new { cashpaymenttype_id = 0, // paymenttypeid cashpaymenttype_name = "", // paymenttypename cashtransaction_amount = grouppaymenttypes.sum(a => != null ? (a.field<int32>("cashtransactionstatus_id") == 1 || a.field<int32>("cashtransactionstatus_id") == 3 ? 1 : -1) * a.field<double>("cashtransaction_amount") : 0.00), }).aggregate(paymenttypestransactions_datatable, (dt, result) => { dt.rows.add(result.cashpaymenttype_id, result.cashpaymenttype_name, result.cashtransaction_amount); return dt; });
this linq works need fields cashpaymenttype_id
, cashpaymenttype_name
within paymenttypes
assuming paymenttypeid - paymenttypename 1-to-1, change group this:
group cashtransactions new { paymenttypeid = paymenttypes.field<int32>("cashpaymenttype_id"), paymenttypename = paymenttypes.field<string>("cashpaymenttype_name") } grouppaymenttypes
the select this:
select new { cashpaymenttype_id = grouppaymenttypes.key.paymenttypeid, cashpaymenttype_name = grouppaymenttypes.key.paymenttypename, ... }
Comments
Post a Comment