-1
public class Order
{
    public int Id;
    public string CustomerName;
    public DateTime OrderDate;
    public List<OrderLine> Lines;
}

public class OrderLine
{
    public decimal Quantity;
    public decimal UnitPrice;
    public Product Product;
}

public class Product
{
    public int Id;
    public string Name;
    public decimal DefaultUnitPrice;
}

我对如何执行此查询感到非常困惑,我试图CustomerName根据订单总数显示升序。提前致谢。

4

2 回答 2

2

怎么样

order.OrderBy(x => x.Lines.Sum(q => q.Quantity * q.UnitPrice));
于 2012-07-03T17:51:11.203 回答
2
(from o in orders
    select new {
    o.CustomerName, 
    Total = o.Lines.Sum(x=>x.UnitPrice*x.Quantity)}
    ).OrderBy(x=>x.CustomerName).ThenBy(x=>x.Total);;

编辑:固定总和

于 2012-07-03T17:54:32.887 回答