Constructing Sort Expression Help Needed

Posts   
 
    
MarcoP avatar
MarcoP
User
Posts: 270
Joined: 29-Sep-2004
# Posted on: 11-Sep-2006 16:16:33   

Hello,

I am constructing a dynamic list using the adapter templates and I have a group by clause to return a count of the results. I need to sort by the 'Count' column, but I can't figure out how to construct the sort expression. Any help would be great!

Jessynoo avatar
Jessynoo
Support Team
Posts: 296
Joined: 19-Aug-2004
# Posted on: 11-Sep-2006 16:53:27   

Hi,

when defining the field for the count column with the agregate, keep track of the corresponding IEntityField(2) (you may use the IEntityFields DefineField() method rather than the ResultSetField factory overloads)

Then you should be able to inject that field in the sortclause constructor.

Now I think that is the simple way, which is clearly subotpimal, since you don't make use of aliasing.

You may have a look at "Expressions in select lists" from the manual.

Using an expression, you may define your master field as an alias for the agregated column (defined in an intermediate field), and reuse the master field.

Cheers

MarcoP avatar
MarcoP
User
Posts: 270
Joined: 29-Sep-2004
# Posted on: 11-Sep-2006 17:02:38   

It looks like the SortClause ctor taking in an IEntityField ref, where define fields returns an IEntityField2.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39927
Joined: 17-Aug-2003
# Posted on: 11-Sep-2006 17:23:29   

Then you're using the selfservicing constructor simple_smile Specify 'null' as second parameter instead.

Frans Bouma | Lead developer LLBLGen Pro
Jessynoo avatar
Jessynoo
Support Team
Posts: 296
Joined: 19-Aug-2004
# Posted on: 11-Sep-2006 17:25:30   

There are different overloads for selfservicing and adapter.

This is also true for Predicates and most objects shared by both scenarios:

The overload for Selfseriving takes an IEntityField argument, where as the one to use with adapter takes IEntityFieldCore + IFieldPersistenceInfo arguments.

You can pass your IEntityField2 as the IEntityFieldCore, and keep the second argument to null since the IEntityField2 object is already more or less a combination of the two and the adapter can take care of updating the persistence data at runtime.

MarcoP avatar
MarcoP
User
Posts: 270
Joined: 29-Sep-2004
# Posted on: 11-Sep-2006 19:46:01   

thx all!