Пример #1
0
        public Expression ApplyNavigation(Expression source, IEnumerable <OeParseNavigationSegment> parseNavigationSegments)
        {
            if (parseNavigationSegments == null)
            {
                return(source);
            }

            Type sourceItemType = OeExpressionHelper.GetCollectionItemType(source.Type);

            foreach (OeParseNavigationSegment parseNavigationSegment in parseNavigationSegments)
            {
                Type selectType;
                ParameterExpression parameter;
                Expression          e;
                if (parseNavigationSegment.NavigationSegment == null) //EntitySetSegment
                {
                    parameter  = Parameter;
                    e          = source;
                    selectType = sourceItemType;
                }
                else
                {
                    parameter = Expression.Parameter(sourceItemType);
                    PropertyInfo navigationClrProperty = sourceItemType.GetTypeInfo().GetProperty(parseNavigationSegment.NavigationSegment.NavigationProperty.Name);
                    e = Expression.MakeMemberAccess(parameter, navigationClrProperty);

                    MethodInfo selectMethodInfo;
                    selectType = OeExpressionHelper.GetCollectionItemType(e.Type);
                    if (selectType == null)
                    {
                        selectType       = e.Type;
                        selectMethodInfo = OeMethodInfoHelper.GetSelectMethodInfo(sourceItemType, selectType);
                    }
                    else
                    {
                        selectMethodInfo = OeMethodInfoHelper.GetSelectManyMethodInfo(sourceItemType, selectType);
                    }

                    LambdaExpression lambda = Expression.Lambda(e, parameter);
                    source = Expression.Call(selectMethodInfo, source, lambda);
                }

                if (parseNavigationSegment.Filter != null)
                {
                    var visitor = new OeQueryNodeVisitor(_visitor, Expression.Parameter(selectType));
                    e = visitor.TranslateNode(parseNavigationSegment.Filter.Expression);
                    LambdaExpression lambda = Expression.Lambda(e, visitor.Parameter);

                    MethodInfo whereMethodInfo = OeMethodInfoHelper.GetWhereMethodInfo(selectType);
                    source = Expression.Call(whereMethodInfo, source, lambda);
                }

                _entityType    = selectType;
                sourceItemType = selectType;
            }

            _visitor = new OeQueryNodeVisitor(_model, Expression.Parameter(_entityType), _visitor.Constans);
            return(source);
        }
Пример #2
0
        public Expression ApplyNavigation(Expression source, IReadOnlyList <OeParseNavigationSegment> parseNavigationSegments)
        {
            if (parseNavigationSegments == null)
            {
                return(source);
            }

            Type sourceItemType = OeExpressionHelper.GetCollectionItemType(source.Type);

            foreach (OeParseNavigationSegment parseNavigationSegment in parseNavigationSegments)
            {
                Type selectType;
                ParameterExpression parameter;
                Expression          e;
                if (parseNavigationSegment.NavigationSegment == null) //EntitySetSegment, KeySegment
                {
                    parameter  = Visitor.Parameter;
                    e          = source;
                    selectType = sourceItemType;
                }
                else
                {
                    parameter = Expression.Parameter(sourceItemType);
                    PropertyInfo navigationClrProperty = sourceItemType.GetPropertyIgnoreCase(parseNavigationSegment.NavigationSegment.NavigationProperty);
                    e = Expression.MakeMemberAccess(parameter, navigationClrProperty);

                    MethodInfo selectMethodInfo;
                    selectType = OeExpressionHelper.GetCollectionItemTypeOrNull(e.Type) ?? e.Type;
                    if (selectType == e.Type)
                    {
                        selectMethodInfo = OeMethodInfoHelper.GetSelectMethodInfo(sourceItemType, selectType);
                    }
                    else
                    {
                        selectMethodInfo = OeMethodInfoHelper.GetSelectManyMethodInfo(sourceItemType, selectType);
                    }

                    LambdaExpression lambda = Expression.Lambda(e, parameter);
                    source = Expression.Call(selectMethodInfo, source, lambda);
                }

                if (parseNavigationSegment.Filter != null)
                {
                    var visitor = new OeQueryNodeVisitor(Visitor, Expression.Parameter(selectType));
                    e = visitor.TranslateNode(parseNavigationSegment.Filter.Expression);
                    LambdaExpression lambda = Expression.Lambda(e, visitor.Parameter);

                    MethodInfo whereMethodInfo = OeMethodInfoHelper.GetWhereMethodInfo(selectType);
                    source = Expression.Call(whereMethodInfo, source, lambda);
                }

                sourceItemType = selectType;
            }

            Visitor.ChangeParameterType(Expression.Parameter(sourceItemType));
            return(source);
        }
        public Expression Build(Expression source, IReadOnlyList <OeSkipTokenNameValue> skipTokenNameValues, OrderByClause uniqueOrderBy)
        {
            OrderProperty[] orderProperties = CreateOrderProperies(source, _visitor, skipTokenNameValues, uniqueOrderBy);
            Expression      filter          = CreateFilterExpression(_visitor, _isDatabaseNullHighestValue, orderProperties);

            LambdaExpression lambda          = Expression.Lambda(filter, _visitor.Parameter);
            MethodInfo       whereMethodInfo = OeMethodInfoHelper.GetWhereMethodInfo(_visitor.Parameter.Type);

            return(Expression.Call(whereMethodInfo, source, lambda));
        }
        public Expression Build(Expression source, String skipToken)
        {
            OrderProperty[] orderProperties = CreateOrderProperies(_skipTokenParser, skipToken);
            Expression      filter          = CreateFilterExpression(source, _visitor, _skipTokenParser.IsDatabaseNullHighestValue, orderProperties);

            LambdaExpression lambda          = Expression.Lambda(filter, _visitor.Parameter);
            MethodInfo       whereMethodInfo = OeMethodInfoHelper.GetWhereMethodInfo(_visitor.Parameter.Type);

            return(Expression.Call(whereMethodInfo, source, lambda));
        }
Пример #5
0
        public Expression ApplyFilter(Expression source, FilterClause filterClause)
        {
            if (filterClause == null)
            {
                return(source);
            }

            Expression       e      = Visitor.TranslateNode(filterClause.Expression);
            LambdaExpression lambda = Expression.Lambda(e, Visitor.Parameter);

            MethodInfo whereMethodInfo = OeMethodInfoHelper.GetWhereMethodInfo(ParameterType);

            return(Expression.Call(whereMethodInfo, source, lambda));
        }
            private MethodCallExpression GetJoin(Expression innerSource, IEdmNavigationProperty navigationProperty)
            {
                Type outerType = OeExpressionHelper.GetCollectionItemType(_outerSource.Type);
                Type innerType = OeExpressionHelper.GetCollectionItemType(innerSource.Type);

                var joinBuilder = new OeJoinBuilder(new OeQueryNodeVisitor(_outerParameterExpression));

                (LambdaExpression outerKeySelector, LambdaExpression innerKeySelector) =
                    joinBuilder.GetJoinKeySelector(outerType, innerType, Array.Empty <IEdmNavigationProperty>(), navigationProperty);

                var        replaceParameterVisitor = new ReplaceParameterVisitor(_outerParameterExpression, outerKeySelector.Parameters[0]);
                Expression outerKeyExpression      = replaceParameterVisitor.Visit(outerKeySelector.Body);
                IReadOnlyList <MemberExpression> outerKeyProperties;
                IReadOnlyList <MemberExpression> innerKeyProperties;

                if (OeExpressionHelper.IsTupleType(outerKeySelector.ReturnType))
                {
                    outerKeyProperties = OeExpressionHelper.GetPropertyExpressions(outerKeyExpression);
                    innerKeyProperties = OeExpressionHelper.GetPropertyExpressions(innerKeySelector.Body);
                }
                else
                {
                    outerKeyProperties = new MemberExpression[] { (MemberExpression)outerKeyExpression };
                    innerKeyProperties = new MemberExpression[] { (MemberExpression)innerKeySelector.Body };
                }

                BinaryExpression?joinExpression = null;

                for (int i = 0; i < outerKeyProperties.Count; i++)
                {
                    if (joinExpression == null)
                    {
                        joinExpression = Expression.MakeBinary(ExpressionType.Equal, outerKeyProperties[i], innerKeyProperties[i]);
                    }
                    else
                    {
                        BinaryExpression equal = Expression.MakeBinary(ExpressionType.Equal, outerKeyProperties[i], innerKeyProperties[i]);
                        joinExpression = Expression.MakeBinary(ExpressionType.AndAlso, joinExpression, equal);
                    }
                }

                MethodInfo       whereMethodInfo = OeMethodInfoHelper.GetWhereMethodInfo(innerType);
                LambdaExpression joinLambda      = Expression.Lambda(joinExpression !, innerKeySelector.Parameters);

                return(Expression.Call(whereMethodInfo, innerSource, joinLambda));
            }
Пример #7
0
        private MethodCallExpression ApplyFilter(Expression source, FilterTransformationNode transformation)
        {
            Type sourceType = OeExpressionHelper.GetCollectionItemType(source.Type);
            ParameterExpression sourceParameter = Expression.Parameter(sourceType);

            var visitor = CreateVisitor(sourceParameter);

            if (_aggProperties.Count > 0)
            {
                visitor.TuplePropertyByAliasName = GetTuplePropertyByAliasName;
            }
            Expression e = visitor.TranslateNode(transformation.FilterClause.Expression);

            MethodInfo       whereMethodInfo = OeMethodInfoHelper.GetWhereMethodInfo(sourceParameter.Type);
            LambdaExpression lambda          = Expression.Lambda(e, sourceParameter);

            return(Expression.Call(whereMethodInfo, source, lambda));
        }