views:

584

answers:

3

I'm new to Linq, what's the syntax for orderby in VB?

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

    qry = qry.OrderBy()

my simple sql statement will be like this:

Select distinct state from zipcodes
order by State
+1  A: 
qry = qry.OrderBy(Function(obj) obj.PropertyToSortBy)
Mehrdad Afshari
A: 

thanks, that works!!!

Here's my final statement: Dim qry = (From lst In cxt.zipcodes _ Select lst.state).Distinct.OrderBy(Function(state) state)

+3  A: 

Alternative syntax for your query (cleaner IMO):

Dim qry = From lst In cxt.zipcodes _
          Select lst.state Distinct _
          Order By state
Meta-Knight