Express SQL OrderBy clause for alphanumeric data in LINQ

I have a SQL Server Reporting Services (SSRS) report that uses SQL collation order byand returns the following strings for alphanumeric data:

Value: 0.0
Value: 20.96
Value: 289.64
Value: 30.99
Value: 308.655
Value: -32296.32
Value: 34.844
Value: 38.95
Value: -697.38
Value: -703.48

Each line has the following format:

`Value: numeric data`

SQL order byseems to sort as a string, but ignores the minus sign in front of the numeric values.

I use C # with LINQ to sort strings to try to match this sort:

var _sorted = _unsortedValues.OrderBy(x => x.Description);

I get:

Value: -32296.32
Value: -697.38
Value: -703.48
Value: 0.0
Value: 20.96
Value: 289.64
Value: 30.99
Value: 308.655
Value: 34.844
Value: 38.95

LINQ sorts bites by default with all minus values, first ascending, then zeros, and then positive values

Any ideas on how to get the desired sort for SSRS sort replication?

NOTE

I have other row types in this report column that are sorted correctly. eg.

"Timestamp: data time data"
"Identifier: string data"
+4
2

, LINQ LINQ , Entity Framework LINQ to sql. , , , OrderBy. , , :

var sorted = _unsortedValues.OrderBy(x => x.Description, StringComparer.InvariantCulture).ToArray();

, SQL.

, , :

var sorted = _unsortedValues.OrderBy(x => x.Description, StringComparer.Ordinal).ToArray();

, ( ).

, , ? , , , .

var sorted = _unsortedValues.OrderBy(x => x.Description, StringComparer.CurrentCulture).ToArray(); // this is what is done by default
+2

, . . 289.64 30.99. , . Regex, Substring , :

var startIndex = "Value: ".Length;
var _sorted = _unsortedValues
                .OrderBy(x => Double.Parse(x.Description.Substring(startIndex)));

. Value: , .

+1

Source: https://habr.com/ru/post/1656188/


All Articles