21

我是 Linq 的新手,VB 中 order by 的语法是什么?

Dim cxt As New datContext
Dim qry = (From lst In cxt.zipcodes _
              Select lst.state).Distinct

    qry = qry.OrderBy()

我的简单 SQL 语句将是这样的:

Select distinct state from zipcodes
order by State
4

3 回答 3

34
qry = qry.OrderBy(Function(obj) obj.PropertyToSortBy)
于 2009-05-26T13:48:03.937 回答
16

查询的替代语法(更清晰的 IMO):

Dim qry = From lst In cxt.zipcodes _
          Select lst.state Distinct _
          Order By state
于 2009-05-26T15:14:04.933 回答
0
Dim cxt As New datContext

Dim qry = (From lst In cxt.zipcodes OrderBy lst.state).Distinct.tolist

Dim statelst = qry.Select(Function(o) o.state).ToList
于 2016-11-06T10:48:45.507 回答