Dear support,
I’m working on a XAF project which is using Domain Components.
I have an order with details, I also have a few fields in order that displays sum fields from details.Something like this:
C#[Calculated("Details.Sum(ToSend)")]
int ToSend { get; }
Until now I was under the impression that if you use servermode for a listview and also use calculated fields, that everything is calculated on the server side. I found out with the profiler that a calculated field produced an extra 4 queries and that it’s much faster to use XPQuery to get the data in the get_field function.
E.g.
C#public int Get_ToSend(IOrder instance, IObjectSpace space)
{
XPQuery<IDetail> q = new XPQuery<IDetail>(((XPObjectSpace)space).Session);
_toSend = (from x in q
where x.Order == instance
select x).Sum(y => y.ToSend);
}
This gives a very neat query with a select sum() and is faster also. But this still produces queries for every order row retrieved.
Is it correct that Calculated not always works on the server side? Or does it only works with Domain Objects?Is there another solution, so I can get one query for every order?I also try using Session.Prefetch but that doesn't make any difference.
Regards and happy xmas.
Hello Rob,
Domain Components is an abstraction layer above XPO, so there should not be any differences in behavior with regular persistent objects.
Calculated properties configured via the Calculated or PersistentAlias attribute are always calculated on the database server side. I would need some additional time to research the exact queries produced by this code, though. Please bear with me.