1

我正在尝试按公司名称对列表进行排序。我已经尝试过以下代码,但这会按 CompID 而不是 CoShort 对列表进行排序。我应该如何将其更改为按 CoShort 排序?

Public Shared Function [SelectCompanyData](iElement() As Integer) As List(Of CompanyList)

    Dim db As New EntryDataContext()

    Dim q As IQueryable(Of CompanyList) = (From Act_Sub_Manfu_Link In db.Act_Sub_Manfu_Links _
            Join Company In db.Companies _
            On Act_Sub_Manfu_Link.CompID Equals Company.CompID _
            Where iElement.Contains(Act_Sub_Manfu_Link.ACCN) _
            And Company.In_Dir _
            Select New CompanyList With { _
                .CompID = Company.CompID, _
                .InDir = Company.In_Dir, _
                .CoShort = Company.CoShort _
                }).Distinct

    q.OrderBy(Function(c) c.CoShort)

    Dim list As List(Of CompanyList) = q.ToList

    Return list

End Function
4

2 回答 2

6

您必须将有序集合分配给一个变量:

Dim oq As IOrderedQueryable(Of CompanyList) = q.OrderBy(Function(c) c.CoShort)

并使用它来获取结果列表:

Dim list As List(Of CompanyList) = oq.ToList()
于 2013-03-26T14:21:07.583 回答
1

除了返回值之外,不需要分配任何东西

Public Function SelectCompanyData(iElement() As Integer) As List(Of CompanyList)
    Dim db As New EntryDataContext()
    Return (From Act_Sub_Manfu_Link In db.Act_Sub_Manfu_Links _
            Join Company In db.Companies _
            On Act_Sub_Manfu_Link.CompID Equals Company.CompID _
            Where iElement.Contains(Act_Sub_Manfu_Link.ACCN) _
            And Company.In_Dir _
            Select New CompanyList With { _
                .CompID = Company.CompID, _
                .InDir = Company.In_Dir, _
                .CoShort = Company.CoShort _
                }).Distinct().OrderBy(Function(c) c.CoShort).ToList()
End Function
于 2013-03-26T15:18:32.397 回答