Fastest way to count number of order lines?

Order is associated with Orderlines. Suppose I want to display the number of orderlines behind each order in the grid, is there a faster way then having a microflow attribute in the order that does the counting with an ''aggregate list' action? [Especially since the microflow has to retrieve the entire list first, this will be sloooooow] If not would writing a Java variation on help?
1 answers

If you're retrieving a list of objects in a microflow and then only use it to perform a list aggregation operation on it, Mendix will automatically optimize this and perform that aggregation directly on the database.

In other words, if you would retrieve the order lines and count them in a microflow, Mendix will only perform a "SELECT COUNT(*) FROM ..." query on the database and never actually retrieve all the order line objects.