コード例 #1
0
        internal OeQueryContext(IEdmModel edmModel, ODataUri odataUri,
                                IEdmEntitySet entitySet, IReadOnlyList <OeParseNavigationSegment> parseNavigationSegments,
                                bool isCountSegment, int pageSize, bool navigationNextLink, bool isDatabaseNullHighestValue,
                                OeMetadataLevel metadataLevel, Db.OeEntitySetAdapter entitySetAdapter)
        {
            EntitySetAdapter           = entitySetAdapter;
            EdmModel                   = edmModel;
            ODataUri                   = odataUri;
            EntitySet                  = entitySet;
            ParseNavigationSegments    = parseNavigationSegments;
            IsCountSegment             = isCountSegment;
            PageSize                   = pageSize;
            NavigationNextLink         = navigationNextLink;
            IsDatabaseNullHighestValue = isDatabaseNullHighestValue;
            MetadataLevel              = metadataLevel;

            var visitor = new OeQueryNodeVisitor(edmModel, Expression.Parameter(entitySetAdapter.EntityType));

            JoinBuilder = new Translators.OeJoinBuilder(visitor);

            if (pageSize > 0 || (odataUri.OrderBy != null && odataUri.Skip != null && odataUri.Top != null))
            {
                SkipTokenNameValues = OeSkipTokenParser.CreateNameValues(edmModel, odataUri.OrderBy, odataUri.SkipToken);
            }
        }
コード例 #2
0
 public OeSelectTranslator(IEdmModel edmModel, OeJoinBuilder joinBuilder, ODataUri odataUri)
 {
     _edmModel           = edmModel;
     _joinBuilder        = joinBuilder;
     _odataUri           = odataUri;
     _rootNavigationItem = new OeNavigationSelectItem(odataUri);
 }
コード例 #3
0
 internal OeSelectTranslator(OeJoinBuilder joinBuilder, OeSelectItem navigationItem)
 {
     _joinBuilder    = joinBuilder;
     _navigationItem = navigationItem;
     _visitor        = joinBuilder.Visitor;
     _metadataLevel  = OeMetadataLevel.None;
 }
コード例 #4
0
        private MethodCallExpression CreateSelectExpression(Expression source, OeJoinBuilder joinBuilder)
        {
            if (_navigationItem.HasNavigationItems)
            {
                return((MethodCallExpression)source);
            }

            if (_navigationItem.SelectItems.Count == 0)
            {
                return((MethodCallExpression)source);
            }

            var expressions = new List <Expression>(_navigationItem.SelectItems.Count);

            for (int i = 0; i < _navigationItem.SelectItems.Count; i++)
            {
                IEdmProperty edmProperty = _navigationItem.SelectItems[i].EdmProperty;
                PropertyInfo clrProperty = OeEdmClrHelper.GetPropertyIgnoreCase(_visitor.Parameter.Type, edmProperty);
                expressions.Add(Expression.MakeMemberAccess(_visitor.Parameter, clrProperty));
            }
            NewExpression newTupleExpression = OeExpressionHelper.CreateTupleExpression(expressions);

            LambdaExpression lambda           = Expression.Lambda(newTupleExpression, _visitor.Parameter);
            MethodInfo       selectMethodInfo = OeMethodInfoHelper.GetSelectMethodInfo(_visitor.Parameter.Type, newTupleExpression.Type);

            return(Expression.Call(selectMethodInfo, source, lambda));
        }
コード例 #5
0
 public OeSelectItemTranslator(OeSelectItem navigationItem, bool navigationNextLink,
                               Expression source, OeJoinBuilder joinBuilder, bool skipToken)
 {
     _navigationItem     = navigationItem;
     _navigationNextLink = navigationNextLink;
     _source             = source;
     _joinBuilder        = joinBuilder;
     _skipToken          = skipToken;
     _visitor            = joinBuilder.Visitor;
 }
コード例 #6
0
        public OeQueryContext(IEdmModel edmModel, ODataUri odataUri)
        {
            EdmModel = edmModel;
            ODataUri = odataUri;

            ParseNavigationSegments = OeParseNavigationSegment.GetNavigationSegments(odataUri.Path);
            EntitySetAdapter        = edmModel.GetEntitySetAdapter((odataUri.Path.FirstSegment as EntitySetSegment).EntitySet);
            var visitor = new OeQueryNodeVisitor(Expression.Parameter(EntitySetAdapter.EntityType));

            JoinBuilder   = new Translators.OeJoinBuilder(visitor);
            MetadataLevel = OeMetadataLevel.Minimal;
        }
コード例 #7
0
        public OeQueryContext(IEdmModel edmModel, ODataUri odataUri, Db.OeEntitySetAdapter entitySetAdapter)
        {
            EdmModel         = edmModel;
            ODataUri         = odataUri;
            EntitySetAdapter = entitySetAdapter;

            var visitor = new OeQueryNodeVisitor(Expression.Parameter(entitySetAdapter.EntityType));

            _joinBuilder            = new Translators.OeJoinBuilder(visitor);
            MetadataLevel           = OeMetadataLevel.Minimal;
            ParseNavigationSegments = Array.Empty <OeParseNavigationSegment>();
            SkipTokenNameValues     = Array.Empty <OeSkipTokenNameValue>();
        }
コード例 #8
0
        public static Expression Build(OeJoinBuilder joinBuilder, Expression source, ParameterExpression parameterExpression, OrderByClause orderByClause)
        {
            while (orderByClause != null)
            {
                MemberExpression propertyExpression = GetPropertyExpression(joinBuilder, source, parameterExpression, orderByClause.Expression);
                LambdaExpression lambda             = Expression.Lambda(propertyExpression, parameterExpression);

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

                orderByClause = orderByClause.ThenBy;
            }

            return(source);
        }
コード例 #9
0
        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);
        }
コード例 #10
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);
        }
コード例 #11
0
        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);
        }
コード例 #12
0
 internal OeSelectTranslator(OeJoinBuilder joinBuilder, OeSelectItem navigationItem)
 {
     _joinBuilder    = joinBuilder;
     _navigationItem = navigationItem;
     _visitor        = joinBuilder.Visitor;
 }
コード例 #13
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());
        }
コード例 #14
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)
            {
                MemberExpression       propertyExpression = Translators.OeOrderByTranslator.GetPropertyExpression(joinBuilder, source, instance, orderByClause.Expression);
                IEdmStructuralProperty edmProperty        = GetEdmProperty(orderByClause.Expression, propertyExpression.Type);
                OePropertyAccessor     accessor;
                if (typeof(OeDynamicType).IsAssignableFrom(propertyExpression.Expression !.Type))
                {
                    PropertyInfo         indexProperty = typeof(OeDynamicType).GetProperty("Item") !;
                    MethodCallExpression expression    = Expression.Call(propertyExpression.Expression !, indexProperty.GetGetMethod() !, Expression.Constant(edmProperty.Name));
                    accessor = OePropertyAccessor.CreatePropertyAccessor(edmProperty, expression, parameter, true);
                }
コード例 #15
0
 public OeExpressionBuilder(Translators.OeJoinBuilder joinBuilder)
 {
     _joinBuilder = joinBuilder;
     Visitor      = joinBuilder.Visitor;
 }
コード例 #16
0
 public OeSelectTranslator(OeJoinBuilder joinBuilder, ODataPath path, OeMetadataLevel metadataLevel) :
     this(joinBuilder, new OeSelectItem(path))
 {
     _metadataLevel = metadataLevel;
 }
コード例 #17
0
        private static Expression BuildOrderBySkipToken(OeSelectItem navigationItem, OrderByClause orderByClause, Expression source, OeJoinBuilder joinBuilder, bool hasSelectItems)
        {
            while (orderByClause != null)
            {
                var propertyNode = (SingleValuePropertyAccessNode)orderByClause.Expression;
                if (propertyNode.Source is SingleNavigationNode navigationNode)
                {
                    OeSelectItem match = null;
                    ExpandedNavigationSelectItem navigationSelectItem = null;
                    do
                    {
                        if ((match = navigationItem.FindHierarchyNavigationItem(navigationNode.NavigationProperty)) != null)
                        {
                            match.AddSelectItem(new OeSelectItem(propertyNode.Property, true));
                            break;
                        }

                        SelectExpandClause selectExpandClause;
                        if (navigationSelectItem == null)
                        {
                            var pathSelectItem = new PathSelectItem(new ODataSelectPath(new PropertySegment((IEdmStructuralProperty)propertyNode.Property)));
                            selectExpandClause = new SelectExpandClause(new[] { pathSelectItem }, false);
                        }
                        else
                        {
                            selectExpandClause = new SelectExpandClause(new[] { navigationSelectItem }, false);
                        }

                        var segment = new NavigationPropertySegment(navigationNode.NavigationProperty, navigationNode.NavigationSource);
                        navigationSelectItem = new ExpandedNavigationSelectItem(new ODataExpandPath(segment), navigationNode.NavigationSource, selectExpandClause);
                    }while ((navigationNode = navigationNode.Source as SingleNavigationNode) != null);

                    if (navigationSelectItem != null)
                    {
                        if (match == null)
                        {
                            match = navigationItem;
                        }

                        var selectItemTranslator = new OeSelectItemTranslator(match, false, source, joinBuilder, true);
                        navigationSelectItem.TranslateWith(selectItemTranslator);
                        source = selectItemTranslator.Source;
                    }
                }
                else
                {
                    if (hasSelectItems)
                    {
                        navigationItem.AddSelectItem(new OeSelectItem(propertyNode.Property, true));
                    }
                }

                orderByClause = orderByClause.ThenBy;
            }

            return(source);
        }
コード例 #18
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)
            {
                MemberExpression       propertyExpression = Translators.OeOrderByTranslator.GetPropertyExpression(joinBuilder, source, instance, orderByClause.Expression);
                IEdmStructuralProperty edmProperty        = GetEdmProperty(orderByClause.Expression, propertyExpression.Type);
                accessors.Add(OePropertyAccessor.CreatePropertyAccessor(edmProperty, propertyExpression, parameter, true));
                orderByClause = orderByClause.ThenBy;
            }

            return(accessors.ToArray());
        }
コード例 #19
0
 public OeExpressionBuilder(Translators.OeJoinBuilder joinBuilder, OeQueryNodeVisitor visitor)
 {
     _joinBuilder = joinBuilder;
     Visitor      = visitor;
 }
コード例 #20
0
 public OeSkipTokenTranslator(OeQueryNodeVisitor visitor, OeJoinBuilder joinBuilder, bool isDatabaseNullHighestValue)
 {
     _visitor     = visitor;
     _joinBuilder = joinBuilder;
     _isDatabaseNullHighestValue = isDatabaseNullHighestValue;
 }