Convert and concatenate in an Expression

Posts   
 
    
danhaigh
User
Posts: 1
Joined: 16-Aug-2007
# Posted on: 16-Aug-2007 21:07:52   

What I'm trying to do is retrieve a derived column which concatenates a numeric field to a text city name. The SQL I'm trying to replicate is:

CAST(code AS varchar(10)) + ' - ' + description AS locdesc

My first pass was:

                Expression descriptionEx = new Expression(" - ", ExOp.Add, LocalFields.Description);
                Expression concatEx = new Expression(LocalFields.Code, ExOp.Add, descriptionEx);
                state.Fields[LocalFields.Description.Name].ExpressionToApply = concatEx;

Which throws an exception (when I fetch) because Code is of type Decimal in the database (SQL Server). No surprise there. But I'm not sure how to do the cast/convert in the expression.

I'm using v2.0.0.0 final.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 17-Aug-2007 09:18:55   

I think it would be easier if you create a custome property for "locdesc" in your entity, which return the needed convertion + cncatenation.