when I put the Order by
clause gives me the error:
An exception of type 'System.NotSupportedException' occurred in System.Data.Linq.ni.dll but was not handled in user code
Additional information: The member 'ExemploDB.Aluno.Nome' has no supported translation to SQL.
Public Sub LoadAlunos()
Dim alunos As List(Of Aluno)
Using db As New AlunoDataContext
alunos = (From aluno In db.Alunos Select aluno Order By aluno.Nome).ToList
lstAlunos.ItemsSource = alunos
End Using
End Sub
My Class Aluno:
<Table()>
Public Class Aluno
<Column(IsPrimaryKey:=True, IsDbGenerated:=True)> _
Private _id As Integer
Public Property ID() As Integer
Get
Return _id
End Get
Set(ByVal value As Integer)
_id = value
End Set
End Property
<Column()>
Private _nome As String
Public Property Nome() As String
Get
Return _nome
End Get
Set(ByVal value As String)
_nome = value
End Set
End Property
<Column()>
Private _cidade As String
Public Property Cidade() As String
Get
Return _cidade
End Get
Set(ByVal value As String)
_cidade = value
End Set
End Property
Public Sub New()
End Sub
Public Sub New(nome As String, cidade As String)
Me.Nome = nome
Me.Cidade = cidade
End Sub
End Class
Any idea?
Try this:
alunos = db.Alunos.ToList().OrderBy(Function(f) f.Nome).ToList()
Added a ToList()
call before the orderby.