Piyush Varma
Piyush Varma

Reputation: 27

List.OrderBy returns a collection of empty strings

I have a collection string date values some of which are empty strings ("").

when I use OrderBy clause, following statement

theList = theList.OrderBy(Function(x) x.age).ToList()

returns empty string collection.

However, if I use OrderByDescending operator, the result is correctly ordered by descending data values.

Sample date values are "2014-10-31 00:00:00.000", "2014-09-30 00:00:00.000", "2014-11-30 00:00:00.000", "", "2014-08-31 00:00:00.000".

What could be the problem please?

Thank you,

Piyush Varma

Upvotes: 0

Views: 326

Answers (1)

EGP
EGP

Reputation: 656

My first instinct would be that if x.billedthru is ever shorter than 10 characters, you could see this behavior. Does it return rows if you try this:

Dim returnCollection As List(Of FundedAccountsDetail) = New List(Of FundedAccountsDetail) 
Select Case sortBy 
Case "billedthru"
   If Ascending = "ASC" Then
      returnCollection = reportCollection.OrderBy(Function(x) x.BilledThru).ToList()
   ElseIf Ascending = "DESC" Then
      returnCollection = reportCollection.OrderByDescending(Function(x) x.BilledThru).ToList() 
   End If
Case Else
      returnCollection = reportCollection
End Select

If it does, then the problem is the substring. If not, I admit that it is perplexing. What I'd probably try is then removing the order by from the first branch of the if and see if it returns rows. Basically work my way back until that branch of the if works and then rebuild it step by step until I start having the problem.

Upvotes: 1

Related Questions