PrefetchPath and paging

Posts   
 
    
methodman
User
Posts: 194
Joined: 24-Aug-2009
# Posted on: 10-Mar-2010 12:53:08   

I need to fetch an entity and first 10 records of an related entity collection.

So far, I've come up with this, but there i no overload which takes page size and page number.



            var entity = new TfProjektyEntity(1);

            var prefetchPath = new PrefetchPath2(EntityType.TfProjektyEntity);
            
            var sort = new SortExpression(TfUlohyFields.Id | SortOperator.Ascending);

            prefetchPath.Add(TfProjektyEntity.PrefetchPathTfUlohy,10,null,null,sort);
            
            adapter.FetchEntity(entity, prefetchPath);


Walaa avatar
Walaa
Support Team
Posts: 14994
Joined: 21-Aug-2005
# Posted on: 10-Mar-2010 17:06:59   

You don't need paging in this case. The specified prefetchPath will return the Top 10 records indeed.

methodman
User
Posts: 194
Joined: 24-Aug-2009
# Posted on: 11-Mar-2010 09:26:09   

The paging is done in memory. There is no paging in the generated SQL. And what if I need the second page ? :-)

Walaa avatar
Walaa
Support Team
Posts: 14994
Joined: 21-Aug-2005
# Posted on: 11-Mar-2010 11:05:12   

Paging can't work with PrefetchPaths.

The way PrefetchPaths work is that it fetchs all related entities in one go and in memory it associates each bunch of entities to its related entity.

For example if you are fetching Customers from Germany, and their Orders. The Framework first fetches the specified Customers, then it collects their ID's and fetches all Orders having CustomerID in the provided list of IDs. (One Query). Then in memory it hook each Order to its specific Customer.

So if you say I want only 10 orders for each Customer, this should be carried out in memory, and there is no room for paging.

If you want paging, then you'll have to drop prefetchpaths, and fetch the orders alone.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39866
Joined: 17-Aug-2003
# Posted on: 12-Mar-2010 10:35:11   

(retracted comment, I read the thread wrong, I thought it was about paging on the main entities, not the related entities.) What Walaa said is correct.

Frans Bouma | Lead developer LLBLGen Pro