ABS function (example for order by)

Hello together,

I'm looking for an easy way to sort my query by ABS values.
I have an integer column with positive and negative values and urgently need the order in ascending order according to the absolute values.

This is a more complex ObjectManager.Find query that I call in a loop.

             .something else
             .OrderBy( abs( MyIntegerField))


Is there something simple here?


Ok, after a few tries I found a solution.
After the first test it works.

Can it be improved further? Or is it good the way it is?
(If ok, you can mark it as "solution")

.AddOrder( TOrder.Asc( TProjections.Sql<Integer>('abs({MyIntegerField})')))

Best regards, Thomas

Yes, that's a good way to do it.
You could also use SQL function mechanism, and register abs as a function. More info here:


But that would be overkill if you just want to use it once like you did.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.