C# 如何使用LINQ对列表进行排序?

C# 如何使用LINQ对列表进行排序?,c#,linq,linq-to-entities,C#,Linq,Linq To Entities,我有一个LINQ查询,用于填充设计师列表 由于我使用下面的过滤器,我的排序没有按我希望的方式运行 我的问题是,考虑到下面的代码,如何最好地在事实之后对列表进行排序,或者在查询时进行排序 我已尝试使用以下脚本在事件发生后对列表进行排序,但收到一个编译器错误: List<TBLDESIGNER> designers = new List<TBLDESIGNER>(); designers = 'calls my procedure below and comes back

我有一个LINQ查询,用于填充设计师列表

由于我使用下面的过滤器,我的排序没有按我希望的方式运行

我的问题是,考虑到下面的代码,如何最好地在事实之后对列表进行排序,或者在查询时进行排序

我已尝试使用以下脚本在事件发生后对列表进行排序,但收到一个编译器错误:

 List<TBLDESIGNER> designers = new List<TBLDESIGNER>();
 designers = 'calls my procedure below and comes back with an unsorted list of designers'
 designers.Sort((x, y) => string.Compare(x.FIRST_NAME, y.LAST_NAME));
列表设计器=新列表();
designers='调用下面的我的过程并返回未排序的设计器列表'
designers.Sort((x,y)=>string.Compare(x.FIRST\u NAME,y.LAST\u NAME));
我的质询如下:

List<TBLDESIGNER> designer = null;

using (SOAE strikeOffContext = new SOAE())
{
   //Invoke the query
   designer = AdminDelegates.selectDesignerDesigns.Invoke(strikeOffContext).ByActive(active).ByAdmin(admin).ToList();
}
列表设计器=null;
使用(SOAE strikeOffContext=new SOAE())
{
//调用查询
designer=AdminDelegates.selectDesignerDesigns.Invoke(strikeOffContext).ByActive(active).ByAdmin(admin).ToList();
}
代表:

public static Func<SOAE, IQueryable<TBLDESIGNER>> selectDesignerDesigns =
        CompiledQuery.Compile<SOAE, IQueryable<TBLDESIGNER>>(
        (designer) => from c in designer.TBLDESIGNER.Include("TBLDESIGN")
                      orderby c.FIRST_NAME ascending
                      select c);
public static Func selectDesigner设计=
CompiledQuery.Compile(
(designer)=>来自designer.TBLDESIGNER.Include(“TBLDESIGN”)中的c
orderby c.FIRST_NAME升序
选择c);
按活动筛选:

public static IQueryable<TBLDESIGNER> ByActive(this IQueryable<TBLDESIGNER> qry, bool active)
    {
        //Return the filtered IQueryable object
        return from c in qry
               where c.ACTIVE == active
               select c;

    }
public static IQueryable ByActive(此IQueryable qry,bool active)
{
//返回过滤后的IQueryable对象
在qry中从c返回
其中c.ACTIVE==ACTIVE
选择c;
}
按管理员筛选:

public static IQueryable<TBLDESIGNER> ByAdmin(this IQueryable<TBLDESIGNER> qry, bool admin)
{
    //Return the filtered IQueryable object
    return from c in qry
           where c.SITE_ADMIN == admin
           select c;

}
public static IQueryable ByAdmin(此IQueryable qry,bool admin)
{
//返回过滤后的IQueryable对象
在qry中从c返回
其中c.SITE_ADMIN==ADMIN
选择c;
}
提前感谢,,
比利

你的帖子里有很多内容,但我选择回答这个问题:

Linq-如何对列表排序

使用声明性OrderBy和ThenBy方法

designers = designers
  .OrderBy(td => td.FirstName)
  .ThenBy(td => td.LastName)
  .ToList();

你的帖子里有很多内容,但我选择回答这个问题:

Linq-如何对列表排序

使用声明性OrderBy和ThenBy方法

designers = designers
  .OrderBy(td => td.FirstName)
  .ThenBy(td => td.LastName)
  .ToList();

您必须命名数据库表TBLDESIGNER吗?哦。如果你必须坚持下去,我会为你感到难过。:-)只是我们使用的命名约定。你为什么说?有更好的图案吗?我想听一下。您必须命名数据库表TBLDESIGNER吗?哦。如果你必须坚持下去,我会为你感到难过。:-)只是我们使用的命名约定。你为什么说?有更好的图案吗?我想听。谢谢戴夫。这正是我最后使用的。谢谢戴夫。这正是我最终使用的。