Return Single Related Entity

Posts   
 
    
gabrielk avatar
gabrielk
User
Posts: 231
Joined: 01-Feb-2005
# Posted on: 28-Aug-2007 10:00:59   

Hi Folks,

I've got the following:

A product catalog with categories & products. Each category contains 1 or more products, now I want to run a query which returns exactly one product per category, this product's picture will be used on the category selection page.

Of course I can just get al CategoryEntities and use their CategoryEntity.ProductCollection[0] entity, but this means ALL products are loaded, while this is not needed. This would be done with a prefetch, but still a lot of overhead.

Running without the prefetch path and to do a GetMulti(filter,1,sort) would mean a query for each category.

I one of my 2 options the one to go, or can the be done more efficient,

Thanks for any help!

Cheers, Gab

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 28-Aug-2007 10:26:53   

Use PrefetchPaths. You can find an overload of the PrefetchPath.Add() method which accepts an int for the maxAmountOfItemsToReturn.

gabrielk avatar
gabrielk
User
Posts: 231
Joined: 01-Feb-2005
# Posted on: 28-Aug-2007 14:02:09   

Thanks