Sorting on the Length of data in a field...

Posts   
 
    
Posts: 34
Joined: 03-Oct-2005
# Posted on: 30-Jan-2006 12:28:01   

Hi

Is it possible to replicate the following SQL Sort Expression in LLBLGen...

ORDER BY Len(field1)

TIA

Matt

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 30-Jan-2006 14:30:46   

Did you try assign a custom IExpression implementation which emits Len() to the field "ExpressionToApply"?

Refer to the following thread please: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=4642

Posts: 34
Joined: 03-Oct-2005
# Posted on: 03-Mar-2006 13:21:52   

I have implemented the FunctionExpression class as described in other threads. However I cannot figure out how to apply this to a sort expression, as the SortClauseFactory.Create only seems to accept a field index, rather than a field entity...


        Dim SortFunction As New FunctionExpression(EntityFieldFactory.Create(ProductFieldIndex.Nng), "LEN")
        Dim SortField As IEntityField2 = ProductFields.Nng.SetExpression(SortFunction)

        ProductsSort.Add(SortClauseFactory.Create(SortField, SortOperator.Descending))


The last line is incorrect. Any more ideas how I can implement this ?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 03-Mar-2006 15:53:05   

Don't use the SortClauseFactory, rather use the SortClause Constructor as follows:

ProductsSort.Add(new SortClause(SortField, null, SortOperator.Descending));