Back to
Latest changes:

This is an old revision of the document!


How to run through query conditions

Sometimes you need to run through all conditions in your query to perform some operation for each condition or to find a particular one. Here is a code snippet which demonstrates this operation:

private void RunThroughConditions(Predicate predicate) {
    foreach (Condition cond in predicate.Conditions) {
        if (cond is SimpleCondition) {
 
            SimpleCondition scond = (SimpleCondition)cond;
 
            if (scond.BaseExpr is EntityAttrExpr) {
                EntityAttrExpr attrExpr = (EntityAttrExpr)scond.BaseExpr;
 
                //here is the attribute of this condition
                EntityAttr attr = attrExpr.Attribute;
 
                //here is condition operator
                Operator op = scond.Operator;
 
                //now we run through all expressions in this condition (except the first one) and check their values
                for (int i = 1; i < scond.Expressions.Count; i++) {
                    Expression expr = scond.Expressions[i];
                    string value = expr.Value;
                    string text = expr.Text;
                }
            }
        }
        else if (cond is Predicate) {
            RunThroughConditions((Predicate)cond);
        }
    }
}
 
.  .  .  .  .  .  .  .  .  .  .
 
//to start the process just call this function for the Root predicate in your Query
RunThroughConditions(query1.Root);

Discussion

, 2013/07/03 16:36
Hello,

How do we add a condition dynamically to the condition panel?
to have a condition in the condition panel when the page loads.


thanks
, 2013/07/03 17:15
You need to add it into Query object and it will appear in QueryPanel automatically.
We have another article about this:
http://docs.korzh.com/easyquery/how-to/add-columns-conditions-by-code
Enter your comment: