jellz77 jellz77 - 1 year ago 65
C# Question

linq how would i order this statement

as you can see, i'm trying to perform multiple order by statements at the end of the statement. my results are not coming back correct.

var query =
(from x in workloadDetail
group x by new { x.titleOrder, x.httitle } into sortedData
select new WorkloadSummary()
httitle = sortedData.Key.httitle,
totalHrs = sortedData.Sum(x => x.totalHrs),
totalDol = sortedData.Sum(x => x.totalDol),
titleOrder = sortedData.Key.titleOrder
}).OrderBy(x => x.httitle).OrderByDescending(x => x.totalHrs);

Answer Source

use ThenByDescending method to apply secondary sorting in descending order.

.OrderBy(x => x.httitle).ThenByDescending(x => x.totalHrs);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download