v3 - adapter, prefetchpath subquery in filter

Posts   
 
    
miloszes
User
Posts: 222
Joined: 03-Apr-2007
# Posted on: 20-Dec-2010 15:38:25   

Hello,

I've got a two tables: A and A_Version

A_Version table stores a copy of A before each modification.

Table A:

ID
SomeOtherColumnToFilter

Table A_Version:

ID
ID_A
Version_Number 

I would like to retrieve an AEntity collection with the latest versions taken from A_Version (the latest Version_Number). As usual I've defined an EntityCollection and prefetch path but unfortunateley I don't know the ID_A in a moment when prefetch path filter is defined. I need it (or maybe there is some other solution) to determine the max value of the version. How can I do that?

Best Regards, MiloszeS

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 20-Dec-2010 16:40:36   

When using the prefetchPath, pass a sortExpression on VersionNumber Descending, and pass 1 for the maxAmountOfItemsToReturn, to issue "Top 1" in the select statment.

Here is the overload of the prefetchPath.Add() mehtod that you should use.

public IPrefetchPathElement Add( 
   IPrefetchPathElement elementToAdd,
   int maxAmountOfItemsToReturn,
   IPredicateExpression additionalFilter,
   IRelationCollection additionalFilterRelations,
   ISortExpression additionalSorter
)
miloszes
User
Posts: 222
Joined: 03-Apr-2007
# Posted on: 20-Dec-2010 17:09:17   

That should work.

Thanks for a help. MiloszeS