ISortExpression & complex Decode sorting

Posts   
 
    
YvesVD
User
Posts: 177
Joined: 19-Oct-2006
# Posted on: 27-Jan-2009 14:56:57   

Hi,

How can I create an ISortExpression in order to support the following statement :

ORDER BY DECODE(TYPE_AKTIE_CD, 'SCHOR', DT_VAN_AKTIE,DT_VAN_BESL)

I'm using an EntityCollection.

Thanks.

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 27-Jan-2009 21:11:08   

You need to use the DBFunctionCall facility to create a Sort Expression - see the documentation here.

This expression can then be passed to the constructor of your SortClause.

Matt

YvesVD
User
Posts: 177
Joined: 19-Oct-2006
# Posted on: 28-Jan-2009 16:03:11   

Hi,

I end up with this piece code

ISortExpression sorter = new SortExpression();
IExpression decodeExpression = new DbFunctionCall("Decode", new object[] { TvnStuitFields.TypeAktieCd, "SCHOR", TvnStuitFields.DtVanAktie, TvnStuitFields.DtVanBesl });
IEntityField2 decodeEntityField = new EntityField2("Test", decodeExpression);
SortClause clause = new SortClause(decodeEntityField, null, SortOperator.Ascending);
sorter.Add(clause);

But this produces ORDER BY "Test" ASC Any idea ?

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 28-Jan-2009 17:05:05   

That's have been added in v.2.6

Where you can set the sortClause's property EmitAliasForExpressionAggregateField to false ref: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=14331

YvesVD
User
Posts: 177
Joined: 19-Oct-2006
# Posted on: 29-Jan-2009 10:16:12   

Any solution for v.2.5 users.

I can't currently upgrade to 2.6 because it also means to upgrade to .Net 3.5.

Thanks

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39859
Joined: 17-Aug-2003
# Posted on: 29-Jan-2009 10:17:40   

YvesVD wrote:

Any solution for v.2.5 users.

I can't currently upgrade to 2.6 because it also means to upgrade to .Net 3.5.

Thanks

No that's not true. v2.6 doesn't require .NET 3.5 at all, in fact it even supports .NET 1.0 still simple_smile

Frans Bouma | Lead developer LLBLGen Pro