problem adding filter PredicateExpression

Posts   
 
    
youkebb
User
Posts: 14
Joined: 14-May-2009
# Posted on: 02-Jun-2009 22:41:49   

Hi I don't quite understand this problem, I am trying to add some expression into the IRelationPredicateBucket to apply filtering on my fetched data collection. something like following:

IRelationPredicateBucket filter = new RelationPredicateBucket(); filter.PredicateExpression.Add(storyId == 1);

and later on i can apply this to a fetch collection, this works perfectly.

But how can we do something like:

IRelationPredicateBucket filter = new RelationPredicateBucket(); filter.PredicateExpression.Add(Headline LIKE '%Basketball%');

or

IRelationPredicateBucket filter = new RelationPredicateBucket(); string s = storyID = 1 AND Headline LIKE '%Basketball%'; filter.PredicateExpression.Add(s);

are those 2 cases doable in the filter? thanks

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 02-Jun-2009 22:52:33   

// C#
IPredicateExpression filter = new PredicateExpression();
filter.Add(YourEntityFields.Headline % "%Basketball%");

' VB.NET
Dim filter As New PredicateExpression()
' SelfServicing
filter.Add(New FieldLikePredicate(YourEntityFields.Headline , "%Basketball%"))
' Adapter
filter.Add(New FieldLikePredicate(YourEntityFields.Headline , Nothing, "%Basketball%"))

' which is equal to (VB.NET 2005)
Dim filter As New PredicateExpression()
filter.Add(YourEntityFields.Headline Mod "%Basketball%")




Your second example.


// C#
IPredicateExpression filter = new PredicateExpression();
filter.Add(YourEntityFields.Headline % "%Basketball%");
filter.AddWithAnd(YourEntityFields.StoryID ==1);

The documentation is here

youkebb
User
Posts: 14
Joined: 14-May-2009
# Posted on: 02-Jun-2009 23:20:42   

Your second example.


// C#
IPredicateExpression filter = new PredicateExpression();
filter.Add(YourEntityFields.Headline % "%Basketball%");
filter.AddWithAnd(YourEntityFields.StoryID ==1);

The documentation is here

Hi thanks for the quick reply. Actually for the second example, I don't have string info at compile time, it's generated dynamically from database. So I have to do something like string s = GetQueryFromDB(); filter.Add(s);

how can I do this? thanks.

MTrinder
User
Posts: 1461
Joined: 08-Oct-2008
# Posted on: 02-Jun-2009 23:43:27   

Unfortunatly, the short answer is "you can't" simple_smile You will have to parse the string yourself, and use the results of the parse to dynamically generate the required predicates.

Matt