在 Linq 中排序 SQL VB.NET 失败

Order by in Linq SQL VB.NET Fail

当我输入 Order by 子句时出现错误:

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

我的 Class 阿鲁诺:

<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

有什么想法吗?

试试这个:

alunos = db.Alunos.ToList().OrderBy(Function(f) f.Nome).ToList()

在 orderby 之前添加了一个 ToList() 调用。