分组后如何排序

chai1338 2014-12-04 04:18:44

DataTable dt_order=BindGrid();
var query = from c in dt_order.AsEnumerable()
group c by new
{
SKU = c.Field<string>("SKU"),
ProductAttributeValueIds = c.Field<string>("ProductAttributeValueIds")
} into g
select new
{
SKU = g.Select(p => p.Field<string>("SKU")).First(),
ProductAttributeValueIds = g.Select(p => p.Field<string>("ProductAttributeValueIds")).First(),
Quantity = g.Sum(p => p.Field<int>("Quantity")),
Total = g.Sum(p => p.Field<int>("Quantity")) * g.Select(p => p.Field<double>("Price")).First(),
Email = string.Join(",", g.Select(p => p.Field<string>("Email"))),
ProductVariantID = g.Select(p => p.Field<int>("ProductVariantID")).First(),
BillingCountryID = string.Join(",", g.Select(p => p.Field<string>("BillingCountryID")))
};
我想根据Total 排序 请问怎么加啊?
...全文
182 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
蝶恋花雨 2014-12-05
  • 打赏
  • 举报
回复
引用 4 楼 wy_9203 的回复:
我怎么记得分组之前要先OrderBy?
在前面和后面都可以。
threenewbee 2014-12-05
  • 打赏
  • 举报
回复
from c in dt_order.AsEnumerable() group c by new { SKU = c.Field<string>("SKU"), ProductAttributeValueIds = c.Field<string>("ProductAttributeValueIds") } into g orderby g.Sum(p => p.Field<int>("Quantity")) * g.Select(p => p.Field<double>("Price")).First() select new { SKU = g.Select(p => p.Field<string>("SKU")).First(), ProductAttributeValueIds = g.Select(p => p.Field<string>("ProductAttributeValueIds")).First(), Quantity = g.Sum(p => p.Field<int>("Quantity")), Total = g.Sum(p => p.Field<int>("Quantity")) * g.Select(p => p.Field<double>("Price")).First(), Email = string.Join(",", g.Select(p => p.Field<string>("Email"))), ProductVariantID = g.Select(p => p.Field<int>("ProductVariantID")).First(), BillingCountryID = string.Join(",", g.Select(p => p.Field<string>("BillingCountryID"))) }
wy_9203 2014-12-05
  • 打赏
  • 举报
回复
我怎么记得分组之前要先OrderBy?
蝶恋花雨 2014-12-04
  • 打赏
  • 举报
回复
(from c in dt_order.AsEnumerable() group c by new { SKU = c.Field<string>("SKU"), ProductAttributeValueIds = c.Field<string>("ProductAttributeValueIds") } into g select new { }).OrderByDescending(x=>x.Total);//.OrderBy(x=>x.Total);
chai1338 2014-12-04
  • 打赏
  • 举报
回复
引用 1 楼 bdmh 的回复:
后面直接OrderBy
}orderby; ? 都敲不出这个词 没智能提示
bdmh 2014-12-04
  • 打赏
  • 举报
回复
后面直接OrderBy

8,497

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 LINQ
社区管理员
  • LINQ
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧