I have a set of results coming back from a Linq to SQL query. Each result has a Name and a SeriesId. The SeriesId can be any value from 1 to N,
So the results might initially come out of the database like this (i.e. any order):
FundA1 FundA6 FundA4 FundC6 FundC3 FundC4 FundB2 FundB7 FundB8 FundB6
I need to get these ordered first by Name, and then by SeriesId but I need to show SeriesId == 6 first, then the rest in any order.
So for example, I need
**FundA6** FundA1 FundA4 **FundB6** FundB2 FundB7 FundB8 **FundC6** FundC3 FundC4
I know it’s possible for me to order by Name and then SeriesId by doing this:
return queryable.OrderBy(f => f.Name).ThenBy(s => s.SeriesId));
but this will order the SeriesId by the lowest value first. Is there a way for me to override this default functionality by specifying that it should order by SeriesId starting at 6 rather than 1?
Try this:
That relies on “false” ordering earlier than “true” – I think it will work… it would in LINQ to Objects, at least.