Linq List.OrderBy返回空字符串的集合

Linq List.OrderBy返回空字符串的集合,linq,sql-order-by,Linq,Sql Order By,我有一个集合字符串日期值,其中一些是空字符串(“”) 当我使用OrderBy子句时,下面的语句 theList=theList.OrderBy(函数(x)x.age).ToList() 返回空字符串集合 但是,如果使用OrderByDescending运算符,则结果将按数据值降序正确排序 样本日期值为“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.000

我有一个集合字符串日期值,其中一些是空字符串(“”)

当我使用OrderBy子句时,下面的语句

theList=theList.OrderBy(函数(x)x.age).ToList()

返回空字符串集合

但是,如果使用OrderByDescending运算符,则结果将按数据值降序正确排序

样本日期值为“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.000”

请问有什么问题

谢谢,


Piyush Varma

我的第一直觉是,如果x.biledthru的长度小于10个字符,你就可以看到这种行为。如果您尝试以下操作,它是否返回行:

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的第一个分支中删除orderby,并查看它是否返回行。基本上,我一直工作到if的分支工作,然后一步一步地重建它,直到我开始出现问题。

请提供真正的代码。您提供的示例不足以看出此处的错误。下面的代码是:Dim returnCollection As List(Of FundeAccountsDetail)=New List(Of FundeAccountsDetail)(Of FundeAccounts)按案例“billedthru”排序选择案例如果升序为Ascending=“ASC”,则returnCollection=reportCollection.OrderBy(函数(x)x.billedthru.Substring(0,10)).ToList()ElseIf Ascending=“DESC”然后returnCollection=reportCollection.OrderByDescending(函数(x)x.biledthru)。ToList()End If Case Else returnCollection=reportCollection End select我删除了子字符串并尝试了您的建议。OrderBy仍然返回所有空字符串。OrderByDescending运行良好!我用“”替换了空值,OrderBy()正在工作!谢谢。