views:

55

answers:

1

Select Year From MyTable Order By Cast( [Year] as Int ) Desc

Same thing I am trying to do in the linq order by. It's not working. I have column that is defined in the data base as string (Varchar) and I need to cast/convert it to integer before I need to sort it. What should be my linq statement?

Thanks in advance.

A: 

Do something like this:

Dim q = (from p in Data.Instance.Context.MyTable 
         select p).OrderBy(Function(p)Convert.ToInt32(p.Year))

The above query was extracted from here.

Leniel Macaferi