problem with sorting

Posts   
 
    
radoF
User
Posts: 3
Joined: 25-Jan-2006
# Posted on: 25-Jan-2006 13:33:25   

Hi, When i pass sorter to EntityCollectionBase.GetMulti method i get an exception, i also appropriate RelationCollection pass to it as well.

Incorrect syntax near the keyword 'ASC'

Sorter looks like : ** int kodRegion = 5; EntityField regionField = (EntityField)new EntityField(); regionField.ExpressionToApply = new Expression( (EntityField) EntityFieldFactory.Create(LokalizaciaFieldIndex.KodRegion), ExOp.Equal, kodRegion);

SortExpression sorter = new SortExpression(); sorter.Add(regionField , SortOperator.Ascending));

**

Could you tell me what's wrong ?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 25-Jan-2006 14:22:02   

EntityField regionField = (EntityField)new EntityField();

Is there a typing mistake in that line?

Will you please show the whole peace of code.... from the EntityCollection creation till the GetMulti() call.

And the generated SQL query and what query do you have in mind instead of the generated one.

Also please explain why do you use a field with an applied expression in the sort clause why not something like this:

SortExpression sorter = new SortExpression();
sorter.Add(SortClauseFactory.Create(LokalizaciaFieldIndex.KodRegion, SortOperator.Ascending));
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39930
Joined: 17-Aug-2003
# Posted on: 25-Jan-2006 14:30:13   

I think that new field is the culprit, it will create ORDER BY ASC instead of ORDER BY fieldname ASC. To work around it, set the Alias property of the field to a value.

Frans Bouma | Lead developer LLBLGen Pro
radoF
User
Posts: 3
Joined: 25-Jan-2006
# Posted on: 25-Jan-2006 15:46:26   

Otis wrote:

I think that new field is the culprit, it will create ORDER BY ASC instead of ORDER BY fieldname ASC. To work around it, set the Alias property of the field to a value.

to set the alias didn't help,

meantime I figured out that there is a problem with comparison operators in ORDER BY expression

radoF
User
Posts: 3
Joined: 25-Jan-2006
# Posted on: 25-Jan-2006 16:00:21   

Will you please show the whole peace of code.... from the EntityCollection creation till the GetMulti() call.

And the generated SQL query and what query do you have in mind instead of the generated one.

Also please explain why do you use a field with an applied expression in the sort clause why not something like this:

I wanted to sort the result of the SQL query the way that all entities with certain kodRegion precede the others, now i think that it would be better to make two SQL queries.