SQL Order Results somewhat alphabetically Entity Framework/C#

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.

Answers


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);

Need Your Help

How to make a splash screen for GUI?

java swing user-interface awt splash-screen

Hi there I'm new to GUIs in Java and was trying to make a splash screen or an image appear for 3 seconds. Then after that it it will go onto my main program. Does anyone have an ideas how to do thi...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.