DbSet按非原始字段排序

时间:2013-10-10 01:45:15

标签: c# asp.net asp.net-mvc entity-framework razor

我正在尝试用Razor在MVC中实现一个排序表,但是我很难让排序工作一些非原始的字段。我的班级模型如下

public class Turma
{
    public int ID { get; set; }
    public string Ano { get; set; }

    [ForeignKey("Professor")]
    public int Professor_ID { get; set; }

    public virtual Professor Professor { get; set; }

    [ForeignKey("Disciplina")]
    public int Disciplina_ID { get; set; }

    public virtual Disciplina Disciplina { get; set; }
}

public class Professor
{
    public int ID { get; set; }
    public string Nome { get; set; }
    public string Email { get; set; }
    public string Telefone { get; set; }
}

public class Disciplina
{
    public int ID { get; set; }
    public string Nome { get; set; }
}

我想用DbSet对它进行排序:

turmas = turmas.OrderByDescending(s => s.Disciplina.Nome);

这甚至可能吗?

0 个答案:

没有答案