Concatenating two fields in a predicate

Posts   
 
    
Isz
User
Posts: 108
Joined: 26-Jan-2006
# Posted on: 18-Feb-2006 15:22:48   

I've been looking around for an answer to this problem but haven't figured out how to make it work, or if there is a better way now with a new updated version of llblgen.

I am trying to perform a search WHERE firstName + " " + lastName LIKE 'john doe'.

One of the articles I saw was:

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

... but Otis suggests there is possibly an easier way now. So far I have a couple expressions like the following:

Expression lastNameExp = new Expression(" ", ExOp.Add, EntityFieldFactory.Create(StudentFieldIndex.LastName));
Expression fullNameExp = new Expression(EntityFieldFactory.Create(StudentFieldIndex.FirstName), ExOp.Add, lastNameExp);

The help file says I might try using FieldCompareExpressionPredicate as in

IPredicate filter = FieldCompareExpressionPredicate(field, ExOp.GreaterThan, rightOperand);

But that doesn't compile because FieldCompareExpressionPredicate is a class. If I added 'new FieldCompareExpressionPredicate()' it wants Comparison.Equal instead of ExOp.Equal, when what I really want is 'LIKE'. So I think I am going down the wrong path maybe.

Is there a way to perhaps just add a new field in the designer that is called FullName and apply an expression there, then just write my predicate around that? If not, how can I best apply the expression above?

Many thanks!

Isz

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39930
Joined: 17-Aug-2003
# Posted on: 18-Feb-2006 15:54:06   

WHERE firstName + " " + lastName LIKE 'john doe' comes down to: WHERE expression LIKE 'john doe'

so what you'll do is this: - create the expression: firstName + " " + lastName - assign that to a field - use that field with a new FieldLikePredicate.

so something like:


// expression
Expression exp = (StudentFields.FirstName + " ") + StudentFields.LastName;
// predicate
Predicate filter = StudentFields.FirstName.SetExpression(ex) % "john doe";

Frans Bouma | Lead developer LLBLGen Pro
Isz
User
Posts: 108
Joined: 26-Jan-2006
# Posted on: 19-Feb-2006 03:55:45   

Thatz Awesome!!!

sunglasses