This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi, I'm trying to retrieve the top 5 entities ordered on a particular attribute. Beyond the paging, I can't seem to find anything that speaks about how to limit results, minimize the query. Thanks!
James
PS - Once I've found those 5, I need to retrieve fields from a bunch of related entities. Should I do that in two seperate queries, or is it the same if I ask for all the information and then use a "TOP N" condition? |
|
|
Use a combination of paging and ordering: Query top5ByScore = new Query LightSpeed will translate the Page.Limit into a TOP n condition on the SELECT (or the equivalent on whatever database you're using; note that some of the "local" databases, e.g. Firebird, VistaDB, SQL CE, have limited or no support for limiting/paging). Regarding retrieving fields from related entities, you can have LightSpeed retrieve related entities in the same query by specifying EagerLoad on the association (or using a named aggregate if you want to load those related entities only conditionally). Note this will retrieve *all* entities related to those returned from the primary query (e.g. if each of your top 5 widgets has 100 grommits associated with it, we will retrieve all 500 grommits, not just the top 5 grommits for each widget). We do not support partial retrieval of associated collections. Also, we do not support loading only specific fields as part of an association eager-load scenario, though you might be able to do it with a combination of lazy loading and named aggregates on the related entity. |
|
|
Great, thanks for the info! |
|