Complex like predicate

Posts   
 
    
studiosoft
User
Posts: 15
Joined: 25-May-2005
# Posted on: 21-May-2008 20:27:46   

Hi, there is some way to build this where clause?

where 'some string value' like [field] + '%'

I can't find the way using FieldLikePredicate.

I'm running version 2.0, on 1.1 .net platform.

Thanks

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 22-May-2008 06:51:12   

Hi studiosoft,

I remember another guy asking this, but I can't find his post. So anyway... I don't know what Database are you using. For T-SQL the LIKE syntax is:

match_expression [ NOT ] LIKE _pattern _[ ESCAPE escape_character ]

where _pattern _ Is the specific string of characters to search for in match_expression, and can include the following valid wildcard characters. pattern can be a maximum of 8,000 bytes.

From that and from my LLBLGen tests I think that's not possible for the moment (I haven't tried with LINQ2LLBL at LLBLGenPro v2.6Beta).

What I could recommend you as a workaround (assuming you are using SQLServer) is rewrite your query like this:

WHERE CHARINDEX( [field], 'some string value') = 1

This has the same efect and nearly identical performance (no tested with large amount of data). This is how your code would looks like (using Adapter):

DbFunctionCall fnChrInx = new DbFunctionCall("CHARINDEX", new object[] { SomeTableFields.SomeField, "some string value"});

IPredicateExpression filter = new PredicateExpression();
filter.Add(SomeTableFields.SomeField.SetExpression(fnChrInx) =1);
David Elizondo | LLBLGen Support Team
studiosoft
User
Posts: 15
Joined: 25-May-2005
# Posted on: 22-May-2008 18:17:05   

First thanks for the answer, nevertheless I'm trying to avoid using database specific function due a portability issues.

Perhaps in the future you can overload then FileLikePredicate constructor to accept an IExpression object in the pattern argument.

Thanks

Walaa avatar
Walaa
Support Team
Posts: 14994
Joined: 21-Aug-2005
# Posted on: 23-May-2008 10:35:28   

Well you may inherit from FieldLikePredicate. And override the ToQueryText() to generate the SQL that you want. Hint: Have a look at FieldLikePredicate.cs in the LLBLGen Pro source code.

A similar thread: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=13125