public static MemberExpression GetPropertyExpression(OeJoinBuilder joinBuilder, Expression source, Expression parameterExpression, SingleValueNode sortProperty)
        {
            if (sortProperty is SingleValuePropertyAccessNode propertyNode)
            {
                return(joinBuilder.GetJoinPropertyExpression(source, parameterExpression, propertyNode));
            }

            if (sortProperty is SingleValueOpenPropertyAccessNode openPropertyNode)
            {
                var propertyExpression      = (MemberExpression)joinBuilder.Visitor.TranslateNode(openPropertyNode);
                var replaceParameterVisitor = new ReplaceParameterVisitor(joinBuilder.Visitor.Parameter, parameterExpression);
                return((MemberExpression)replaceParameterVisitor.Visit(propertyExpression));
            }

            throw new InvalidOperationException("Unknown type order by expression " + sortProperty.GetType().Name);
        }
Exemple #2
0
        public static Expression Build(OeJoinBuilder joinBuilder, Expression source, ParameterExpression parameterExpression, OrderByClause orderByClause)
        {
            while (orderByClause != null)
            {
                var              propertyNode = (SingleValuePropertyAccessNode)orderByClause.Expression;
                Expression       keySelector  = joinBuilder.GetJoinPropertyExpression(source, parameterExpression, propertyNode);
                LambdaExpression lambda       = Expression.Lambda(keySelector, parameterExpression);

                MethodInfo orderByMethodInfo = GetOrderByMethodInfo(source, orderByClause.Direction, parameterExpression.Type, keySelector.Type);
                source = Expression.Call(orderByMethodInfo, source, lambda);

                orderByClause = orderByClause.ThenBy;
            }

            return(source);
        }
Exemple #3
0
        public static OePropertyAccessor[] GetAccessors(Expression source, OrderByClause orderByClause, Translators.OeJoinBuilder joinBuilder)
        {
            var accessors = new List <OePropertyAccessor>();

            ParameterExpression parameter = Expression.Parameter(typeof(Object));
            UnaryExpression     instance  = Expression.Convert(parameter, OeExpressionHelper.GetCollectionItemType(source.Type));

            while (orderByClause != null)
            {
                var propertyNode = (SingleValuePropertyAccessNode)orderByClause.Expression;
                MemberExpression propertyExpression = joinBuilder.GetJoinPropertyExpression(source, instance, propertyNode);
                accessors.Add(OePropertyAccessor.CreatePropertyAccessor(propertyNode.Property, propertyExpression, parameter, true));
                orderByClause = orderByClause.ThenBy;
            }

            return(accessors.ToArray());
        }
        public static Expression BuildNested(OeJoinBuilder joinBuilder, Expression source, ParameterExpression parameterExpression, OrderByClause orderByClause,
                                             IReadOnlyList <IEdmNavigationProperty> joinPath)
        {
            while (orderByClause != null)
            {
                var        propertyNode = (SingleValuePropertyAccessNode)orderByClause.Expression;
                Expression?keySelector  = joinBuilder.GetJoinPropertyExpression(source, joinBuilder.Visitor.Parameter, joinPath, propertyNode.Property);
                if (keySelector == null)
                {
                    throw new InvalidOperationException("Sorting EdmProperty " + propertyNode.Property.Name + " not found in source");
                }

                LambdaExpression lambda            = Expression.Lambda(keySelector, parameterExpression);
                MethodInfo       orderByMethodInfo = GetOrderByMethodInfo(source, orderByClause.Direction, parameterExpression.Type, keySelector.Type);
                source = Expression.Call(orderByMethodInfo, source, lambda);

                orderByClause = orderByClause.ThenBy;
            }

            return(source);
        }