I have a XPO domain object Order which has a association with OrderLine. In order I have a property Profit which is implemented as
public decimal Profit
{
get
{
decimal result = 0;
foreach (OrderLine ol in this.OrderLines)
{
result += ol.Profit.AsMoney() * ol.Quantity;
}
return result;
}
}
but this causes a listing of orders to execute a query per orderline for each order. How can I either load the collection of orderlines in a second query and join them in memory or if that is not feasible some way prevent the loading of the Profit property until it is actually accessed?