c# - Can my two linq lines of code be combined? -
i'm not sure how since i'm familiar basic form or linq.
here 2 sets of code:
var qry = x in customerschecks.customerscheckslist x.routingnumber == routingnumber && x.bankaccountnumber == bankaccountnumber && x.branch > 0 && x.accountnumber > 0 orderby x.name select x; var qry2 = qry.groupby(x => new { x.branch, x.accountnumber}).select(x => x.first()).tolist();
ultimately, want first query in order of branch + account number distinctly.
can combined or have way this?
thanks in advanced!
the quick , dirty solution add groupby
chain end of first query.
var qry = (from x in customerschecks.customerscheckslist x.routingnumber == routingnumber && x.bankaccountnumber == bankaccountnumber && x.branch > 0 && x.accountnumber > 0 orderby x.name select x).groupby(x => new { x.branch, x.accountnumber}) .select(x => x.first()) .tolist();
or following incorrupating group exist query syntax
var qry = (from x in customerschecks.customerscheckslist x.routingnumber == routingnumber && x.bankaccountnumber == bankaccountnumber && x.branch > 0 && x.accountnumber > 0 orderby x.name group x new { x.branch, x.accountnumber} grp select grp.first()).tolist();
Comments
Post a Comment