1

使用以下查询

 Dim allEvents As New List(Of Events)
 Dim digits = "1 2 3 4 5 6 7 8 9 0".Split()
 Dim results = (From t In ctx.events
                           Where t.date = todaysdate.Date AndAlso
                           Not digits.Any(Function(d) (t.symbol.Contains(d)))
                           Order By t.time
                           Select New With {
                                  t.symbol,
                                  t.date, t.time,
                                  t.description,
                                  t.domestic_call_num,
                                  t.web_url})

             If results.Count > 0 Then
                For x As Integer = 0 To results.Count - 1
                    Dim newevent As New Events
                    With newevent
                        .CompanySymbol = results(x).symbol
                        .EventDate = results(x).date
                        .EventTime = Left(results(x).time.ToString(), 5)
                        .EventDescription = results(x).description
                        If results(x).domestic_call_num IsNot Nothing Then
                            .DialInNumber = results(x).domestic_call_num
                        Else
                            .DialInNumber = ""
                        End If
                        If results(x).web_url IsNot Nothing Then
                            .WebCastUrl = results(x).web_url
                        Else
                            .WebCastUrl = ""
                        End If
                    End With
                    allEvents.Add(newevent)
                Next
                Return allEvents

我得到了我想要的结果,但我想按描述和时间进一步排序

我尝试了以下,这应该有效

 Dim results = (From t In ctx.events
                           Where t.date = todaysdate.Date AndAlso
                           Not digits.Any(Function(d) (t.symbol.Contains(d)))
                           Order By t.time
                           Group By t.description
                           Select New With {
                                  t.symbol,
                                  t.date, t.time,
                                  t.description,
                                  t.domestic_call_num,
                                  t.web_url})

我还尝试了编译器不喜欢的 ThenBy。任何有关如何实现此目的的帮助将不胜感激。本质上,我想要一个时间排序,然后是描述,然后是符号。

4

2 回答 2

2

使用集成语法时,您可以这样写:

Order By t.time, t.description
Select New With {
     ...

有关详细信息,请参阅ThenBy 的查询表达式示例

于 2013-06-26T17:26:19.683 回答
1

您可以尝试在查询结束时像这样订购您的物品:

 Dim results = (From t In ctx.events
                       Where t.date = todaysdate.Date AndAlso
                       Not digits.Any(Function(d) (t.symbol.Contains(d)))
                       Select New With {
                              t.symbol,
                              t.date, t.time,
                              t.description,
                              t.domestic_call_num,
                              t.web_url}).OrderBy(Function(r) r.time)
                                         .ThenBy(Function(r) r.description)

在查询中这样做可能会更快。

于 2013-06-26T17:33:32.293 回答