一聚教程网:一个值得你收藏的教程网站

热门教程

LINQ 中SQL Group By排序

时间:2022-06-25 03:51:36 编辑:袖梨 来源:一聚教程网

实际上不是,分组后需要重新排序。

 代码如下 复制代码

using(DBDataContext db = new DBDataContext()){
        var matches = from t in db.tProjectOutlays
                      where
                      (!string.IsNullOrEmpty(key1.Text) ? t.Name.Contains(key1.Text.Trim()) : true)
                      group t by t.CostingID into p
                      select new
                      {
                          ID = t.id,
                          Name = t.Name,
                      };
        gv.DataSource = matches.OrderByDescending(t => t.ID);
        gv.DataBind();
}
 

热门栏目