how should C# linq orderby thenby be used? [closed]

Your code has no ordering.

What it has is code to generate a new query to order a list – but that is never executed.

sortingList.OrderBy(m => m.RoleId)
             .ThenBy(m => m.ToolbarLocation)
             .ThenBy(m => m.Band)
             .ThenBy(m => m.BandIndex);

The return of these calls is an IQueryable that has to be executed. You never do .OrderBy etc. do NOT change the input data.

A foreach, ToList etc. materializes the new result set.

Browse More Popular Posts

Leave a Comment