How to use FieldLikePredicate

Posts   
 
    
tedh
User
Posts: 34
Joined: 14-Dec-2006
# Posted on: 19-Feb-2007 05:59:49   

Sorry, but I am not understanding how to apply the correct syntax for FieldLikePredicate expression for the scenario below.

I am using LLBLGenPro 2 and SelfServicing model.

The following example is found in the documentation on page 187:

filter.Add(CustomerFields.CompanyName % "Solution%");

Now what if our pattern is not a literal value. What if the user is prompted for the pattern and the pattern is then contained in the variable txtPrompt.Text

What is the correct syntax to handle the following:

filter.Add(CustomerFields.CompanyName % txtPrompt.Text + "%");

Here, txtPrompt.Text is only known at run time.

Thanks tedh

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 19-Feb-2007 06:56:20   

What is the correct syntax to handle the following:

filter.Add(CustomerFields.CompanyName % txtPrompt.Text + "%");

Here, txtPrompt.Text is only known at run time.

That's correct! you can do that. .Net Compiler replace the string variable txtPrompt.Text for a constant (at runtime, of course flushed ): If at sometime txtPrompt.Text contains "ACB", the WHERE CLAUSE will seems to CompanyName like 'ABC%', and so on.

However, to match the expression with a valid IPredicate, you must add parenthesis:

filter.Add(CustomerFields.CompanyName % (txtPrompt.Text + "%") );

Good luck! wink

David Elizondo | LLBLGen Support Team
tedh
User
Posts: 34
Joined: 14-Dec-2006
# Posted on: 19-Feb-2007 20:52:57   

Thank you very much.

Worked perfectly.