conditional IExpression for calculated TypedList field

Posts   
 
    
Jamanga
User
Posts: 93
Joined: 21-Jul-2006
# Posted on: 01-Nov-2008 05:51:45   

Hi,

I have a calculated field within a TypedList I wish to display. I went through this link: http://llblgen.com/TinyForum/Messages.aspx?ThreadID=8110&StartAtMessage=0&#62541 and it works great!

I'm concatenating 2 fields (ResourceFields.Title and ResourceFields.Showname) as follows:

IExpression myTest = new Expression( 
       new Expression( ResourceFields.Title, ExOp.Add, " - "),
         ExOp.Add, ResourceFields.Showname);
fields.DefineField(new EntityField2("FullTitle", myTest2), index);

To make this a bit tidier, I'd really like to do is examine the ResourceFields.Showname value, and if its null/empty, not display the "-" at all.

What is the best way to do this?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 01-Nov-2008 07:53:48   

You could include a CASE plus ISNULL DBFunctionCall expression to the formula:

DbFunctionCall dashShowname = new DbFunctionCall("CASE ISNULL({0}, '') WHEN '' THEN '' ELSE ' - ' + {1} END", 
     new object[]{ ResourceFields.Showname, ResourceFields.Showname});

IExpression myTest = new Expression( ResourceFields.Title, ExOp.Add, dashShowname);

fields.DefineField(new EntityField2("FullTitle", myTest2), index);
David Elizondo | LLBLGen Support Team
Jamanga
User
Posts: 93
Joined: 21-Jul-2006
# Posted on: 01-Nov-2008 08:08:48   

Thanks David that worked perfectly.. yet another cool feature I've learnt about!