我正在尝试编写一条语句以获取Entity Framework中两个字段的乘积之和。
给出以下结构:
public class Order
{
public int OrderNUmber {get; set;}
public virtual List<Orderline> OrderLines {get; set;}
public virtual List<ServiceLine> ServiceLines {get; set;}
public string someproperty {get; set;}
}
public class OrderLine
{
public string productname {get; set;}
public int quantity {get; set;}
public decimal price {get; set;}
}
public class ServiceLine
{
public string servicename {get; set;}
public int quantity {get; set;}
public decimal rate {get; set;}
}
我试图在一个查询中返回总订单价值:
var GrandTotal = Orders.Where(q => q.someproperty == "somecondition")
.Sum(order =>
order.OrderLines.Sum(line => line.quantity * line.price)
+ order.ServiceLines.Sum(sl =>sl.quantity * sl.rate));
但是,此版本的点不会得到正确的总数。这个数字比预期的要少。