Luís Tiago Luís Tiago - 1 year ago 114
C# Question

Order decimals in LINQ

I'm using entity framework to get data from a table and sort that data by a decimal column
How do i order that data in the correct way in linq?
i allready tried

list.OrderBy(x => x.DisplayOrder)

but this gives a wrong result


Thanks for the help

Answer Source

Is your DisplayOrder a string? If so it is ordering it by the alphabetic order instead if the numeric. Parse to decimal:

list.OrderBy(x => decimal.Parse(x.DisplayOrder))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download