jellz77 jellz77 - 4 months ago 7
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

use ThenByDescending method to apply secondary sorting in descending order.

.OrderBy(x => x.httitle).ThenByDescending(x => x.totalHrs);
Comments