about FieldLikePredicate

Posts   
 
    
Posts: 14
Joined: 09-Sep-2007
# Posted on: 16-Apr-2008 16:26:29   

hi, i have a table aaa that has id and pattern fields. and i wanna generate the query like this :

aaa

id patern name code ...................

1 A%B 2 C%D 3 A%B 4 C%D 5 E%F

select * from aaa where 'A23434234B' like patern

result must be first and third records.

how can i generate this query with llbl expresions. thank you

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 16-Apr-2008 17:08:53   

If you execute the above query manually against the database would it return the first and thrid row?

Posts: 14
Joined: 09-Sep-2007
# Posted on: 16-Apr-2008 22:54:08   

yes

Posts: 14
Joined: 09-Sep-2007
# Posted on: 17-Apr-2008 08:56:33   

Is it possible to generate expression like this? if not how can manage it?

string str = "A23434234B'";

IPredicateExpression filter = new PredicateExpression(); filter.Add(str % aaaFields.Patern);

Thank you

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 17-Apr-2008 11:15:52   

So the idea is the order of the field vs the value, right?

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.

Posts: 14
Joined: 09-Sep-2007
# Posted on: 17-Apr-2008 13:39:27   

i inherited the FieldLikePredicate and overrided ToQueryText() function. and with a strategy i changed the order of the parameters

queryText.AppendFormat(null, "{0} LIKE {1}", 
                    base.DatabaseSpecificCreator.CreateFieldName(_field, _persistenceInfo, _field.Name, _objectAlias, ref uniqueMarker, inHavingClause), 
                    parameter.ParameterName);

to

queryText.AppendFormat(null, "{0} LIKE {1}", parameter.ParameterName ,
                        base.DatabaseSpecificCreator.CreateFieldName(_field, _persistenceInfo, _field.Name, _objectAlias, ref uniqueMarker, inHavingClause) );

it is done for now simple_smile

thank you