コード例 #1
0
            protected override Expression VisitBinary(BinaryExpression node)
            {
                switch (node.NodeType)
                {
                case ExpressionType.Equal:
                    var constantExpression = node.Right as ConstantExpression;
                    if (constantExpression == null)
                    {
                        throw new NotSupportedException(Resources.KeySelectorVisitor_VisitBinary_The_right_operand_of_a_binary_expression_must_be_a_constant);
                    }

                    var primaryKey = MemberEvaluator.Evaluate(node.Left);
                    _primaryKeys.Add(primaryKey, constantExpression.Value == null ? "@" : constantExpression.Value.ToString());
                    return(node);

                case ExpressionType.And:
                    return(base.VisitBinary(node));

                case ExpressionType.AndAlso:
                    return(base.VisitBinary(node));

                default:
                    throw new NotSupportedException(string.Format(Resources.KeySelectorVisitor_VisitBinary_Expressions_of_type_0_are_not_supported_in_primary_key_predicates, node.NodeType));
                }
            }
コード例 #2
0
            /// <summary>
            /// Visits the member.
            /// </summary>
            /// <param name="member">The member.</param>
            /// <returns></returns>
            protected override Expression VisitMember(MemberExpression member)
            {
                if (member.Member.DeclaringType == typeof(QueryContext))
                {
                    _filterExpression.Append(QueryContextEvaluator.Evaluate(member));
                    return(member);
                }

                _filterExpression.Append(MemberEvaluator.Evaluate(member));
                return(member);
            }
コード例 #3
0
            private Expression VisitStaticEnumerableContainsMethodCall(MethodCallExpression methodCall)
            {
                var member = MemberEvaluator.Evaluate(methodCall.Arguments[1]);

                _filterExpression.Append(member);
                _filterExpression.Append("=");
                var enumerable    = (IEnumerable)((ConstantExpression)methodCall.Arguments[0]).Value;
                var operandValues = (from object operandValue in enumerable select(operandValue ?? "@").ToString()).ToArray();

                _filterExpression.Append(operandValues.Any() ? string.Join(",", operandValues) : "@");
                return(methodCall);
            }
コード例 #4
0
        protected virtual Expression VisitOrderByMethodCall(MethodCallExpression methodCall, string direction)
        {
            Visit(methodCall.Arguments[0]);

            if (SortExpression.Length > 0)
            {
                _sortExpression.Append(',');
            }

            _sortExpression.Append('@');
            _sortExpression.Append(MemberEvaluator.Evaluate(methodCall.Arguments[1]));
            _sortExpression.Append(" ");
            _sortExpression.Append(direction);
            return(methodCall);
        }
コード例 #5
0
            private Expression VisitDirectPredicateMethodCall(MethodCallExpression methodCall)
            {
                if (methodCall.Method.Name != "Member")
                {
                    throw new NotSupportedException();
                }

                var dataObjectType = methodCall.Method.DeclaringType.GetGenericArguments().First();

                _filterExpression.Append("!");
                _filterExpression.Append(dataObjectType.Name);
                _filterExpression.Append(".");
                _filterExpression.Append(MemberEvaluator.Evaluate(methodCall.Arguments.First()));
                return(methodCall);
            }
コード例 #6
0
            private Expression VisitStaticEnumerableAnyMethodCall(MethodCallExpression methodCall)
            {
                if (methodCall.Arguments.Count != 2)
                {
                    throw new NotSupportedException();
                }

                var member = MemberEvaluator.Evaluate(methodCall.Arguments[0]);

                _filterExpression.Append(member);
                _filterExpression.Append(".");
                int?queryId;
                var predicate = Translate(methodCall.Arguments[1], out queryId);

                _filterExpression.Append(predicate);
                return(methodCall);
            }
コード例 #7
0
            protected override Expression VisitMethodCall(MethodCallExpression methodCall)
            {
                if (methodCall.Method.DeclaringType != typeof(Enumerable))
                {
                    throw new NotSupportedException(string.Format(Resources.VisitMethodCall_The_method_call_0_on_type_1_is_not_supported, methodCall.Method.Name, methodCall.Method.DeclaringType));
                }

                if (methodCall.Method.Name != "Contains")
                {
                    throw new NotSupportedException(string.Format(Resources.VisitMethodCall_The_method_call_0_on_type_1_is_not_supported, methodCall.Method.Name, methodCall.Method.DeclaringType));
                }

                var memberExpression = methodCall.Arguments[0] as MemberExpression;

                if (memberExpression == null || memberExpression.Member.DeclaringType != typeof(QueryContext))
                {
                    throw new NotSupportedException();
                }

                switch (memberExpression.Member.Name)
                {
                case "WritableAdministrativeUnitIds":
                    _filterExpression.Append(MemberEvaluator.Evaluate(methodCall.Arguments[1]));
                    _filterExpression.Append("=");
                    _filterExpression.Append("|AI_RED|");
                    break;

                case "ActiveAdministrativeUnitSubHierarchyIds":
                    _filterExpression.Append(MemberEvaluator.Evaluate(methodCall.Arguments[1]));
                    _filterExpression.Append("=");
                    _filterExpression.Append("|AI_UND|");
                    break;

                case "ActiveAdministrativeUnitHierarchyIds":
                    _filterExpression.Append(MemberEvaluator.Evaluate(methodCall.Arguments[1]));
                    _filterExpression.Append("=");
                    _filterExpression.Append("|AI_FULL|");
                    break;

                default:
                    throw new NotSupportedException(string.Format(Resources.QueryContextVisitor_VisitMethodCall_The_method_0_on_1_is_not_supported, methodCall.Method.Name, methodCall.Method.DeclaringType));
                }
                return(methodCall);
            }
コード例 #8
0
        protected virtual Expression VisitIncludeMethodCall(MethodCallExpression methodCall)
        {
            Visit(methodCall.Arguments[0]);

            var lambda = (LambdaExpression)StripQuotes(methodCall.Arguments[1]);

            var memberPath                   = MemberEvaluator.Evaluate(lambda.Body);
            var memberPathElements           = memberPath.Split('.');
            var memberExpressionPathElements = UnwindMemberAccess(lambda.Body).Reverse().ToList();

            for (var memberPathElementIndex = 0; memberPathElementIndex < memberPathElements.Length; memberPathElementIndex++)
            {
                var partialMemberLambdaBody = memberExpressionPathElements[memberPathElementIndex];
                var partialMemberLambda     = Expression.Lambda(partialMemberLambdaBody, lambda.Parameters.ToArray());

                ProcessIncludeSelector(partialMemberLambda);
            }
            return(methodCall);
        }
コード例 #9
0
            private Expression VisitStringMethodCall(MethodCallExpression methodCall)
            {
                _filterExpression.Append(MemberEvaluator.Evaluate(methodCall.Object));
                _filterExpression.Append("=");
                switch (methodCall.Method.Name)
                {
                case "StartsWith":
                    return(VisitStringStartsWithMethodCall(methodCall));

                case "EndsWith":
                    return(VisitStringEndsWithMethodCall(methodCall));

                case "Contains":
                    return(VisitStringContainsMethodCall(methodCall));

                default:
                    throw new NotSupportedException(string.Format(Resources.VisitMethodCall_The_method_call_0_on_type_1_is_not_supported, methodCall.Method.Name, methodCall.Method.DeclaringType));
                }
            }
コード例 #10
0
        protected virtual void ProcessIncludeSelector(LambdaExpression lambda)
        {
            var memberPath = MemberEvaluator.Evaluate(lambda.Body);

            if (_includeSelectors.ContainsKey(memberPath))
            {
                return;
            }

            if (typeof(IDataObjectCollection).IsAssignableFrom(lambda.Body.Type))
            {
                var memberSelector = lambda.Compile();
                _includeSelectors.Add(memberPath, memberSelector);
                return;
            }

            if (typeof(INotifyPropertyChanged).IsAssignableFrom(lambda.Body.Type))
            {
                _relatedObjects.Add(memberPath);
                var memberSelector = lambda.Compile();
                _includeSelectors.Add(memberPath, memberSelector);
            }
        }