LINQ/C#子查询 公共类秩序 { 公共int Id; 公共字符串客户名称; 公共日期时间订单日期; 公共列表行; } 公共类命令行 { 公共小数数量; 公共十进制单价; 公共产品; } 公共类产品 { 公共int Id; 公共字符串名称; 公共单位价格; }
对于如何进行此查询,我感到非常困惑,我正试图根据订单总数升序显示LINQ/C#子查询 公共类秩序 { 公共int Id; 公共字符串客户名称; 公共日期时间订单日期; 公共列表行; } 公共类命令行 { 公共小数数量; 公共十进制单价; 公共产品; } 公共类产品 { 公共int Id; 公共字符串名称; 公共单位价格; },c#,linq,sql-order-by,subquery,C#,Linq,Sql Order By,Subquery,对于如何进行此查询,我感到非常困惑,我正试图根据订单总数升序显示CustomerName。 提前谢谢。怎么样 public class Order { public int Id; public string CustomerName; public DateTime OrderDate; public List<OrderLine> Lines; } public class OrderLine { public decimal Quant
CustomerName
。
提前谢谢。怎么样
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和count(订单)?订单总金额(货币),订单总数量?订单总金额(货币)。谢谢你的回复,我可能已经把它做好了。所以当你意识到哪一个是解决方案时,请接受它。欢迎来到StackOverflow!;)除非你想用单价乘以数量。(取决于OP实际想要得到什么。)
order.OrderBy(x => x.Lines.Sum(q => q.Quantity * q.UnitPrice));
(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);;