Add SORT BY expression to GROUP BY function

Posts   
 
    
KIT
User
Posts: 59
Joined: 04-Apr-2007
# Posted on: 05-Jul-2007 10:38:43   

Hi!

I want to build the following SQL with LLBLGen


SELECT addressID, COUNT(*) as c
FROM [order]
GROUP BY addressID
ORDER BY c desc

The only problem is the ORDER BY expression. I don't know how to do that. This is my code:


ResultsetFields fields = new ResultsetFields(2);
fields.DefineField(OrderFields.AddressId, 0, "SumOfAmount");
fields[0].AggregateFunctionToApply = AggregateFunction.Count;
fields.DefineField(OrderFields.AddressId, 1);

GroupByCollection groupBy = new GroupByCollection();
groupBy.Add(EntityFieldFactory.Create(OrderFieldIndex.AddressId));

ISortExpression sortExpression = new SortExpression();
sortExpression.Add(new SortClause(fields[0], SortOperator.Descending)); // not compilable!!!

DataTable results = new DataTable();
mAdapter.FetchTypedList(fields, results, filter, 10, sortExpression, true, groupBy);

The code line new SortClause(fields[0], SortOperator.Descending) is not compilable! Error message is: Argument type 'SD.LLBLGen.Pro.ORMSupportClasses.IEntityField2' is not assignable to parameter type 'SD.LLBLGen.Pro.ORMSupportClasses.IEntityField'

I found examples on the internet with exactly the same code. So I guess something has changed in LLBLGen 2. What's the correct code? smile

Thanks in advance for your support.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 05-Jul-2007 10:49:38   

Argument type 'SD.LLBLGen.Pro.ORMSupportClasses.IEntityField2' is not assignable to parameter type 'SD.LLBLGen.Pro.ORMSupportClasses.IEntityField'

IEntityField2 is used for the Adapter model (which you are using as appears to me). IEntityField is used for the SelfServicing model.

So it appears that you are using a wrong overload of the SortClause constructor, a one specific for the SelfServicing. Try the following instead.

sortExpression.Add(new SortClause(fields[0], null,  SortOperator.Descending));
KIT
User
Posts: 59
Joined: 04-Apr-2007
# Posted on: 05-Jul-2007 10:54:30   

That's it! simple_smile Thanks!

Unbelievable good support. Answer in 10 minutes! Incredible! smile