当我尝试返回此日期列表
时,继续得到错误的结果更新
Private Shared Function GetDistinctDates(ByRef ctx As ToolkitEntities,
ByVal symbol As String,
ByVal interval As Integer,
Optional isRangeProj As Boolean = False) As List(Of Date)
Dim numDates As Integer = 0
If isRangeProj = True Then
numDates = 3
Else
numDates = TakeValue(interval)
End If
Dim dates = (From data In ctx.tsintracharts
Where data.Symbol = symbol
Select data.Date).Distinct().ToList()
'Dim datelist As IQueryable(Of Date) = dates.OrderByDescending(Function(o) o).Take(numDates)
Return dates
End Function
没有排序,返回整个日期列表
我之前按日期排序,都使用函数语法,并在Linq语句中的Select之前放置OrderBy。我只是想在不同的日期列表中返回最新的三个日期。
但是,如果我将Order By移动到LINQ语句中,则不会发生排序
Dim dates = (From data In ctx.tsintracharts
Where data.Symbol = symbol
Order By data.Date Descending
Select data.Date
).Distinct()
并返回dates.Take(numDates)确实只返回三个日期。问题是它们总是最老的,我需要最新的。
答案 0 :(得分:0)
Private Shared Function GetDistinctDates(ByRef ctx As ToolkitEntities,
ByVal symbol As String,
ByVal interval As Integer,
Optional isRangeProj As Boolean = False) As List(Of Date)
Dim numDates As Integer = 0
If isRangeProj = True Then
numDates = 3
Else
numDates = TakeValue(interval)
End If
Dim dates As List(Of Date) = (From d In ctx.tsintracharts
Where d.Symbol = symbol
Select d.Date).Distinct().ToList()
Dim datelist As New List(Of Date)
For x As Integer = 1 To dates.Count
If x > (dates.Count - numDates) Then
datelist.Add(dates(x - 1))
End If
Next
Return datelist
End Function