Exemple #1
0
        /**
         * Return a new query based on this query with an additional where clause added.
         * @param json Json representation of the where clause.
         * @return A new EntityQuery.
         */
        public EntityQuery Where(String json)
        {
            var qmap = JsonConvert.DeserializeObject <Dictionary <string, object> >(json);
            var pred = BasePredicate.PredicateFromMap(qmap);

            return(this.Where(pred));
        }
Exemple #2
0
        /**
         * Materializes the serialized json representation of an EntityQuery.
         * @param json The serialized json version of the EntityQuery.
         */
        public EntityQuery(String json)
        {
            if (json == null || json.Length == 0)
            {
                return;
            }
            Dictionary <string, object> qmap;

            try {
                var dmap = JsonHelper.Deserialize(json);
                qmap = (Dictionary <string, object>)dmap;
            } catch (Exception) {
                throw new Exception(
                          "This EntityQuery ctor requires a valid json string. The following is not json: "
                          + json);
            }

            this._resourceName       = GetMapValue <string>(qmap, "resourceName");
            this._skipCount          = GetMapInt(qmap, "skip");
            this._takeCount          = GetMapInt(qmap, "take");
            this._wherePredicate     = BasePredicate.PredicateFromMap(GetMapValue <Dictionary <string, object> >(qmap, "where"));
            this._orderByClause      = OrderByClause.From(GetMapValue <List <Object> >(qmap, "orderBy"));
            this._selectClause       = SelectClause.From(GetMapValue <List <Object> >(qmap, "select"));
            this._expandClause       = ExpandClause.From(GetMapValue <List <Object> >(qmap, "expand"));
            this._parameters         = GetMapValue <Dictionary <string, object> >(qmap, "parameters");
            this._inlineCountEnabled = GetMapValue <bool?>(qmap, "inlineCount");
        }
Exemple #3
0
        public static IQueryable ApplyWhere(IQueryable source, Type elementType, BasePredicate predicate)
        {
            var method     = TypeFns.GetMethodByExample((IQueryable <String> q) => q.Where(s => s != null), elementType);
            var lambdaExpr = predicate.ToLambda(elementType);
            var func       = BuildIQueryableFunc(elementType, method, lambdaExpr);

            return(func(source));
        }
Exemple #4
0
 /**
  * Copy constructor
  * @param query
  */
 public EntityQuery(EntityQuery query)
 {
     this._resourceName       = query._resourceName;
     this._skipCount          = query._skipCount;
     this._takeCount          = query._takeCount;
     this._wherePredicate     = query._wherePredicate;
     this._orderByClause      = query._orderByClause;
     this._selectClause       = query._selectClause;
     this._expandClause       = query._expandClause;
     this._inlineCountEnabled = query._inlineCountEnabled;
     this._parameters         = query._parameters;
 }
Exemple #5
0
        /**
         * Return a new query based on this query with an additional where clause added.
         * @param predicate A Predicate representing the where clause to add.
         * @return A new EntityQuery.
         */
        public EntityQuery Where(BasePredicate predicate)
        {
            EntityQuery eq = new EntityQuery(this);

            if (eq._wherePredicate == null)
            {
                eq._wherePredicate = predicate;
            }
            else if (eq._wherePredicate.Operator == Operator.And)
            {
                AndOrPredicate andOrPred = (AndOrPredicate)eq._wherePredicate;
                var            preds     = new List <BasePredicate>(andOrPred.Predicates);
                preds.Add(predicate);
                eq._wherePredicate = new AndOrPredicate(Operator.And, preds);
            }
            else
            {
                eq._wherePredicate = new AndOrPredicate(Operator.And,
                                                        eq._wherePredicate, predicate);
            }
            return(eq);
        }
        private static BasePredicate PredicateFromKeyValue(String key, Object value)
        {
            Operator op = Operator.FromString(key);

            if (op != null)
            {
                if (op.OpType == OperatorType.AndOr)
                {
                    var preds2 = PredicatesFromObject(value);
                    return(new AndOrPredicate(op, preds2));
                }
                else if (op.OpType == OperatorType.Unary)
                {
                    BasePredicate pred = PredicateFromObject(value);
                    return(new UnaryPredicate(op, pred));
                }
                else
                {
                    throw new Exception("Invalid operator in context: " + key);
                }
            }

            if (value == null || TypeFns.IsPredefinedType(value.GetType()))
            {
                return(new BinaryPredicate(BinaryOperator.Equals, key, value));
            }
            else if (value is IDictionary <string, object> && ((IDictionary <string, object>)value).ContainsKey("value"))
            {
                return(new BinaryPredicate(BinaryOperator.Equals, key, value));
            }

            if (!(value is Dictionary <string, object>))
            {
                throw new Exception("Unable to resolve value associated with key:" + key);
            }

            var preds = new List <BasePredicate>();
            var map   = (Dictionary <string, object>)value;


            foreach (var subKey in map.Keys)
            {
                Operator      subOp  = Operator.FromString(subKey);
                Object        subVal = map[subKey];
                BasePredicate pred;
                if (subOp != null)
                {
                    if (subOp.OpType == OperatorType.AnyAll)
                    {
                        BasePredicate subPred = PredicateFromObject(subVal);
                        pred = new AnyAllPredicate(subOp, key, subPred);
                    }
                    else if (subOp.OpType == OperatorType.Binary)
                    {
                        pred = new BinaryPredicate(subOp, key, subVal);
                    }
                    else
                    {
                        throw new Exception("Unable to resolve OperatorType for key: " + subKey);
                    }
                    // next line old check was for null not 'ContainsKey'
                }
                else if (subVal is IDictionary <string, object> && ((IDictionary <string, object>)subVal).ContainsKey("value"))
                {
                    pred = new BinaryPredicate(BinaryOperator.Equals, key, subVal);
                }
                else
                {
                    throw new Exception("Unable to resolve BasePredicate after: " + key);
                }
                preds.Add(pred);
            }
            return(CreateCompoundPredicate(preds));
        }
Exemple #7
0
 public WhereBuilder(BasePredicate predicate)
 {
 }
 public UnaryPredicate(Operator op, BasePredicate predicate) : base(op)
 {
     Predicate = predicate;
 }
 public AnyAllPredicate(Operator op, Object exprSource, BasePredicate predicate) : base(op)
 {
     ExprSource = exprSource;
     Predicate  = predicate;
 }