I have a list of data that looks like so:
What I want to do is use LINQ to order by option code, then by any box sizes that start with 'W', then order by the rest of the box sizes. The ordered list should look order exactly how it is shown above.
What I have Tried 1:
var check = _routeManagementService.GetAllOptionsWithBoxSizes().Select(x => new OptionDataViewModel
{
Id = x.Id,
BoxSizeId = x.BoxSizeId,
Name = x.Name,
OptionCode = x.OptionCode,
BoxSize = x.BoxSize,
Time = x.Time
}).OrderBy(x => x.OptionCode).ThenBy(x => x.BoxSize).ToList();
What I have Tried 2:
var check = _routeManagementService.GetAllOptionsWithBoxSizes().Select(x => new OptionDataViewModel
{
Id = x.Id,
BoxSizeId = x.BoxSizeId,
Name = x.Name,
OptionCode = x.OptionCode,
BoxSize = x.BoxSize,
Time = x.Time
}).OrderBy(x => x.OptionCode)
.ThenBy(x => x.BoxSize.StartsWith("W"))
.ThenBy(x => x.BoxSize).ToList();
In Either case the initial option code sort would work but then it would still show box sizes containing F first before ones containing W. How can I write this linq query to correctly sort the list in the way I want?
Thank you for any suggestions or comments!