Remove a predicate from a PredicateExpression object

Posts   
 
    
Naleo
User
Posts: 6
Joined: 11-Oct-2004
# Posted on: 25-Nov-2004 14:20:52   

Hello,

I would like to know if it was possible to remove a predicate once this one has been added to a PredicateExpression object. This object only contains Add method for adding new predicates, but not delete method.

Thanks

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39930
Joined: 17-Aug-2003
# Posted on: 25-Nov-2004 14:49:49   

Remove is not implemented as it would cause some problems with the operators as well: say you have 3 predicates and 2 operators in the expression: A op1 B op2 C. You want to remove B. Which operator has to be removed as well? op1 or op2?

So what's best is to create a new one, and you can loop through the predicateexpression elements using a forloop and add the predicateexpressionelement objects from the old to the new predicateexpression object using something like:

PredicateExpression newEx = new PredicateExpression(); for(int i=0;i<oldEx.Count;i++) { newEx.Add(oldEx[i]); }

This is schematic, as you of course have to use the proper AddWith... calls based on the operators you run into while traversing oldEx.

Frans Bouma | Lead developer LLBLGen Pro
mikeg22
User
Posts: 411
Joined: 30-Jun-2005
# Posted on: 05-Apr-2006 19:44:28   

I have a situation where I would like to go through a predicateexpression and make replacements to the predicateexpressionelements in some situations. I'm guess the above is the way to do this, but is there any possibility of just implementing a Replace(...) in the predicateexpression class?

EDIT: I just noticed that the Filter property on PrefetchPathElement is readonly. So, I can't do what I want to do anyways. Aren't there situations where the Filter should need to be replaced or changed in a way that goes beyond adding to it?

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 06-Apr-2006 02:25:18   

Usually the logic is placed at the insertion time for the predicate. What is your scenario that is causing you issues? Maybe there is an alternative to changing an expression.

mikeg22
User
Posts: 411
Joined: 30-Jun-2005
# Posted on: 06-Apr-2006 04:05:20   

bclubb wrote:

Usually the logic is placed at the insertion time for the predicate. What is your scenario that is causing you issues? Maybe there is an alternative to changing an expression.

I'm intercepting a PrefetchPath and trying to make security related changes to it, like joining to certain sercurity tables where appropriate. I've resorted to rebuilding the entire PrefetchPath graph though, because runtime insertions into the PreficateExpressions is impossible disappointed

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 06-Apr-2006 08:41:30   

I would have suggested to rebuild the predicateExpression.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39930
Joined: 17-Aug-2003
# Posted on: 06-Apr-2006 10:46:27   

mikeg22 wrote:

bclubb wrote:

Usually the logic is placed at the insertion time for the predicate. What is your scenario that is causing you issues? Maybe there is an alternative to changing an expression.

I'm intercepting a PrefetchPath and trying to make security related changes to it, like joining to certain sercurity tables where appropriate. I've resorted to rebuilding the entire PrefetchPath graph though, because runtime insertions into the PreficateExpressions is impossible disappointed

I have the feeling what you want IS possible, though I can't help you with the current info you provided wink . Could you elaborate more specifically what you want to do and where you ran into a wall?

Frans Bouma | Lead developer LLBLGen Pro
mikeg22
User
Posts: 411
Joined: 30-Jun-2005
# Posted on: 06-Apr-2006 16:54:52   

Otis wrote:

mikeg22 wrote:

bclubb wrote:

Usually the logic is placed at the insertion time for the predicate. What is your scenario that is causing you issues? Maybe there is an alternative to changing an expression.

I'm intercepting a PrefetchPath and trying to make security related changes to it, like joining to certain sercurity tables where appropriate. I've resorted to rebuilding the entire PrefetchPath graph though, because runtime insertions into the PreficateExpressions is impossible disappointed

I have the feeling what you want IS possible, though I can't help you with the current info you provided wink . Could you elaborate more specifically what you want to do and where you ran into a wall?

Sure,

One thing we do is row level security. For a table 'Employee' there is another table 'EmployeeIDsForUser' that has username,employeeid. For any prefetch path that includes a filter on 'Employee', I need to AND each particular Predicate on a (select employeeid where employeeid in (select emplloyeeid from EmployeeIDsForUser where username=@username). Each filter predicate should be subject to this "narrowing."

I would love to be able to go through filters, pull out those looking at the employee table, turn them into predicateexpressions, and add a FieldCompareSetPredicate (I think thats what its called, the one for 'select x where x in (...)) to it with an AND.

What would you suggest?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39930
Joined: 17-Aug-2003
# Posted on: 07-Apr-2006 11:05:44   

A predicate expression consists of PredicateExpressionElement objects. Say I: - Add FieldCompareValuePredicate - AddWithAnd FieldLikePredicate

This will lead to 3 PredicateExpressionElement objects in the expression, the first for the comparevalue predicate, the second for the and operator and the third for the like predicate.

Now, if you want to change the comparevalue predicate into a fieldcomparesetpredicate, you simply first grab the PredicateExpressionElement object. It has two properties: Type and Contents. Type is a simple flag which tells the predicatexpression evaluator what kind of element it is: an operator or a predicate. In this case, it's a predicate. You then grab the Contents, and convert it into a FieldCompareSetPredicate, you then simply set the Contents property of the PredicateExpressionElement object to that FieldCompareSetPredicate and you're done.

It is key to do this before the persistence info is added to the predicate expression, which is done at a late point in time so it's likely you are manipulating it before the persistence info is added to the predicateexpression.

Frans Bouma | Lead developer LLBLGen Pro
mikeg22
User
Posts: 411
Joined: 30-Jun-2005
# Posted on: 07-Apr-2006 16:19:48   

Otis wrote:

A predicate expression consists of PredicateExpressionElement objects. Say I: - Add FieldCompareValuePredicate - AddWithAnd FieldLikePredicate

This will lead to 3 PredicateExpressionElement objects in the expression, the first for the comparevalue predicate, the second for the and operator and the third for the like predicate.

Now, if you want to change the comparevalue predicate into a fieldcomparesetpredicate, you simply first grab the PredicateExpressionElement object. It has two properties: Type and Contents. Type is a simple flag which tells the predicatexpression evaluator what kind of element it is: an operator or a predicate. In this case, it's a predicate. You then grab the Contents, and convert it into a FieldCompareSetPredicate, you then simply set the Contents property of the PredicateExpressionElement object to that FieldCompareSetPredicate and you're done.

It is key to do this before the persistence info is added to the predicate expression, which is done at a late point in time so it's likely you are manipulating it before the persistence info is added to the predicateexpression.

Ahh! Replace the Contents instead of the element itself...I wish I had thought of that sooner, I already wrote code to completely rebuild the prefetch path element. Oh well, live and learn!

Thanks simple_smile