当我尝试返回此日期列表时,总是得到错误的结果
更新
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
不发生排序,返回整个日期列表
我之前按日期排序过,既使用函数语法,也通过将 OrderBy 放在 linq 语句中的 Select 之前。我只是尝试返回不同日期列表中的最新三个日期。
但是,如果我将排序方式移动到 LINQ 语句中,则不会发生排序
Dim dates = (From data In ctx.tsintracharts
Where data.Symbol = symbol
Order By data.Date Descending
Select data.Date
).Distinct()
和返回日期。Take(numDates) 实际上只返回三个日期。问题是它们总是最古老的,我需要最新的。
哇,很蹩脚,但它有效。任何能改进这种方法的人都会成为我的英雄,因为我确信有比这个答案描述的方法更好的方法来完成这个。
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