开发者

devexpress XPO calculated property on child collection select n + 1

开发者 https://www.devze.com 2023-03-24 12:38 出处:网络
I have a XPO domain object Order which has a association with OrderLine. In order I have a property Profit which is implemented as

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
    {
        decima开发者_运维技巧l 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?


You can use the Session Prefetch method to accomplish your task

Session.PreFetch(ObjectList, "OrderLines");  

Also consider looking at this sample from DevExpress Code Central E305. There the calculated property is being cached. In result the performance is increased more

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号