Concatenation using expressions

Posts   
 
    
JMitchell avatar
JMitchell
User
Posts: 128
Joined: 01-Sep-2006
# Posted on: 02-Aug-2007 17:35:26   

In a thread here: http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=3503&HighLight=1

Otis mentions operator overloading being made simpler in the new version of LLBLGen (This was back in 2005)

What's the best way to do this in LLBLGen Pro 2.0:

            // Fields
            ResultsetFields fields = new ResultsetFields(2);
            fields.DefineField(VehiclesFieldIndex.VehicleId, 0, "VehicleId");
            fields.DefineField(VehiclesFieldIndex.Model, 1, "VehicleFullname");

            Expression modelExp = new Expression(" ", ExOp.Add, EntityFieldFactory.Create(VehiclesFieldIndex.Model));
            Expression fullExp = new Expression(EntityFieldFactory.Create(ManufacturersFieldIndex.Name), ExOp.Add, modelExp);
            fields[1].ExpressionToApply = fullExp;

(Code taken from the linked article. I'm using VB.NET 2005 with self servicing but I'm sure the code will be about the same for either language.

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 03-Aug-2007 09:34:12   

Here is a shorter form:

            Expression someExp = new Expression(" ", ExOp.Add, VehicleFields.Model);
            Expression fullExp = new Expression(ManufacturersFields.Name, ExOp.Add, someExp);
            fields[1].ExpressionToApply = fullExp;

You may also try the following short version:

            fields[1].ExpressionToApply = new Expression(ManufacturersFields.Name + new Expression(" " + VehicleFields.Model));