Your last OrderBy
blows away your first. You're ordering the list by dept
, then re-ordering the result by subdept
.
What you want to use here is ThenBy
to preserve the first ordering.
Your code would look like this:
return inventoryItems.Where(d => d.dept >= deptStartWhole).Where(e => e.subdept >= startFraction)
.Where(f => f.dept <= deptEndWhole)
.Where(g => g.subdept >= endFraction)
.OrderBy(o => o.dept)
.ThenBy(s => s.subdept);