Field expressions and aggregates - Max in Predicate

Posts   
 
    
ianvink
User
Posts: 394
Joined: 15-Dec-2006
# Posted on: 11-Jul-2007 15:21:39   

I have a simple entity

Customer.Country Customer.SomeNumber

How would I get the Customer entity from the DB with Country='Canada' and with Max(SomeNumber)

I read the 'Field expressions and aggregates', but couldn't figure that out using a ResultsetFields object in a predicate.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 11-Jul-2007 15:47:45   

Would you please post the SQL query that you want to execute? And whether you want to fetch it in an entity or a dynamicList (Using ResultsetFileds)

ianvink
User
Posts: 394
Joined: 15-Dec-2006
# Posted on: 11-Jul-2007 15:52:15   

Hi Wala,

Entity.

SELECT   TOP 1 *
FROM        Customer
Where     Country = 'Canada'
ORDER BY SomeNumber DESC

Gives me the top SomeNumber in Canada.

Right now I just use a CustomerCollection.GetMulti() and pass in a predicate for Canada and a sort clause. I was hoping there was an easier way.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 11-Jul-2007 16:15:26   

For the above query: I doubt you can find an easier way than using GetMulti(). Especially if you want to fetch an entity. Otherwise you can use a DynamicList to fetch any fields you want from the Customer table, you will have to supply the filter (country == 'Canada'), a Sorter too and a Top 1 (maxNumberOfItemsToReturn). // not an easier solution IMHO.