Esempio n. 1
0
 /// <summary>
 ///     Returns a locator for the member being queried upon
 /// </summary>
 /// <param name="mapping"></param>
 /// <param name="expression"></param>
 /// <returns></returns>
 protected virtual string GetLocator(IDocumentMapping mapping, MethodCallExpression expression)
 {
     if (!expression.Method.IsStatic && expression.Object != null && expression.Object.NodeType != ExpressionType.Constant)
     {
         // x.member.Equals(...)
         return mapping.JsonLocator(expression.Object);
     }
     if (expression.Arguments[0].NodeType == ExpressionType.Constant)
     {
         // string.Equals("value", x.member)
         return mapping.JsonLocator(expression.Arguments[1]);
     }
     // string.Equals(x.member, "value")
     return mapping.JsonLocator(expression.Arguments[0]);
 }
Esempio n. 2
0
        private IWhereFragment buildSimpleWhereClause(IDocumentMapping mapping, BinaryExpression binary)
        {
            var isValueExpressionOnRight = binary.Right.IsValueExpression();
            var jsonLocatorExpression = isValueExpressionOnRight ? binary.Left : binary.Right;
            var valuExpression = isValueExpressionOnRight ? binary.Right : binary.Left;

            var op = _operators[binary.NodeType];

            var value = valuExpression.Value();

            if (mapping.PropertySearching == PropertySearching.ContainmentOperator &&
                binary.NodeType == ExpressionType.Equal && value != null)
            {
                return new ContainmentWhereFragment(_serializer, binary);
            }

            var jsonLocator = mapping.JsonLocator(jsonLocatorExpression);

            if (value == null)
            {
                var sql = binary.NodeType == ExpressionType.NotEqual
                    ? $"({jsonLocator}) is not null"
                    : $"({jsonLocator}) is null";

                return new WhereFragment(sql);
            }
            if (jsonLocatorExpression.NodeType == ExpressionType.Modulo)
            {
                var moduloByValue = GetModuloByValue(binary);
                return new WhereFragment("{0} % {1} {2} ?".ToFormat(jsonLocator, moduloByValue, op), value);
            }


            return new WhereFragment("{0} {1} ?".ToFormat(jsonLocator, op), value);
        }