コード例 #1
0
        /// <summary> Translate the EntityQuery expression into a JSON string </summary>
        public static string Translate(Expression expression, out string parameters)
        {
            var visitor = new JsonQueryExpressionVisitor();

            visitor.VisitRoot(expression);

            var jsonSettings = new JsonSerializerSettings {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
                ContractResolver      = new CamelCasePropertyNamesContractResolver(),
                NullValueHandling     = NullValueHandling.Ignore
                                        //ContractResolver = Json.QueryContractResolver.Instance
            };

            var json = JsonConvert.SerializeObject(visitor, Formatting.None, jsonSettings);

            //without a server-side custom model binder for 'Customer?{"parameters":{"companyName":"C"}}' I cannot have parameters with right values,
            //so I have to use this hack
            if (visitor.Parameters?.Count > 0)
            {
                parameters = string.Join("&", visitor.Parameters.Select(kvp => string.Format("{0}={1}", kvp.Key, Uri.EscapeDataString(kvp.Value))));
            }
            else
            {
                parameters = null;
            }

            return(json);
        }
コード例 #2
0
        /// <summary> Translate the EntityQuery expression into a JSON string </summary>
        public static string Translate(Expression expression)
        {
            var visitor = new JsonQueryExpressionVisitor();

            visitor.VisitRoot(expression);

            var jsonSettings = new JsonSerializerSettings {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
                ContractResolver      = new CamelCasePropertyNamesContractResolver(),
                NullValueHandling     = NullValueHandling.Ignore
                                        //ContractResolver = Json.QueryContractResolver.Instance
            };

            var json = JsonConvert.SerializeObject(visitor, Formatting.None, jsonSettings);

            return(json);
        }