This page has been moved, the new location is https://korzh.com/easyquery/docs/how-to/run-through-query-conditions?.

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);