LINQ 中SQL Group By排序

作者:袖梨 2022-06-25

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

 代码如下 复制代码

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();
}
 

相关文章

精彩推荐