问题描述:

I want to sort the rows of data by a label (string). The label is one or more uppercase letters.

For example: A -> Z followed by AA, AB, AC ....... ZZ

I want the order displayed to be A, B, C ..... X, Y, Z, AA, AB, AC ....... BA, BB, BC ...... ZX, ZY, ZZ

In this case the ID of the row is not guaranteed to be in the correct order, so I cannout use the rows identity.

Is this possible? I would like to be able to do this in C#/Entity Framework lambda Expression if possible.

网友答案:

Simply order by the length of that string then by the string itself:

var query = data.OrderBy(item => item.Field.Length)
    .ThenBy(item => item.Field);
相关阅读:
Top