retrieve PredicateExpression from database field?

Posts   
 
    
youkebb
User
Posts: 14
Joined: 14-May-2009
# Posted on: 23-Jul-2009 00:09:31   

Hi, I am working with an EntityCollection. The EntityCollection need to be filtered and I used

IRelationPredicateBucket filter = new RelationPredicateBucket(); filter.PredicateExpression.Add(WiremessageFields.WireServiceId == wireServiceID); filter.PredicateExpression.AddWithAnd(WiremessageFields.Headline == 's' | WiremessageFields.Category == 'q');

to add filter entries. I have no problem to add filters this way. The problem is, the filter information in my case was stored in a database table field. For example the previous code will be stored in a field:

WireServiceID = 1 AND (Category = 's' OR Category ='q')

I want to apply these filters on to the EntityCollection when I fetch it. Apparently I cannot directly add this string to the PredicateExpression. I am trying to do something like filter.PredicateExpression.Add(" WireServiceID = 1 AND (Category = 's' OR Category ='q')");

Is there a way to do this? Thanks.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 23-Jul-2009 02:47:11   

There's no direct way to do that, as the entities should be query agnostic. You should try some parser out there (GOLD parser, for instance), then create a method that translate your string into IPredicateExpression and return that. Is the better/clean solution I can think for this.

David Elizondo | LLBLGen Support Team
youkebb
User
Posts: 14
Joined: 14-May-2009
# Posted on: 24-Jul-2009 15:30:40   

daelmo wrote:

There's no direct way to do that, as the entities should be query agnostic. You should try some parser out there (GOLD parser, for instance), then create a method that translate your string into IPredicateExpression and return that. Is the better/clean solution I can think for this.

Hi, thanks for the reply. Instead of using the parser, I think the following will also work. extract the filter info from DB and put it into part of the T-sql script. Then create a SqlCommand object, call ExecuteReader() to get all qualified rows. Then create a entity collection EntityCollection<WiremessageEntity> wires = new EntityCollection<WiremessageEntity>();

and we can call wires.Add(wire); in a while loop to add rows one by one.