Пример #1
0
        public OeQueryContext CreateQueryContext(ODataUri odataUri, int pageSize, bool navigationNextLink, OeMetadataLevel metadataLevel)
        {
            List <OeParseNavigationSegment> navigationSegments = null;

            if (odataUri.Path.LastSegment is KeySegment ||
                odataUri.Path.LastSegment is NavigationPropertySegment)
            {
                navigationSegments = new List <OeParseNavigationSegment>();
                ODataPathSegment previousSegment = null;
                foreach (ODataPathSegment segment in odataUri.Path)
                {
                    if (segment is NavigationPropertySegment navigationSegment)
                    {
                        navigationSegments.Add(new OeParseNavigationSegment(navigationSegment, null));
                    }
                    else if (segment is KeySegment)
                    {
                        IEdmEntitySet previousEntitySet;
                        var           keySegment = segment as KeySegment;
                        navigationSegment = null;
                        if (previousSegment is EntitySetSegment)
                        {
                            var previousEntitySetSegment = previousSegment as EntitySetSegment;
                            previousEntitySet = previousEntitySetSegment.EntitySet;
                        }
                        else if (previousSegment is NavigationPropertySegment)
                        {
                            navigationSegment = previousSegment as NavigationPropertySegment;
                            previousEntitySet = (IEdmEntitySet)navigationSegment.NavigationSource;
                        }
                        else
                        {
                            throw new InvalidOperationException("invalid segment");
                        }

                        FilterClause keyFilter = CreateFilterClause(previousEntitySet, keySegment.Keys);
                        navigationSegments.Add(new OeParseNavigationSegment(navigationSegment, keyFilter));
                    }
                    previousSegment = segment;
                }
            }

            if (pageSize > 0)
            {
                odataUri.Top = pageSize;
                IEdmEntityType edmEntityType = GetEntityType(odataUri.Path, navigationSegments);
                odataUri.OrderBy = OeSkipTokenParser.GetUniqueOrderBy(_edmModel, edmEntityType, odataUri.OrderBy, odataUri.Apply);
            }

            var           entitySetSegment = (EntitySetSegment)odataUri.Path.FirstSegment;
            IEdmEntitySet entitySet        = entitySetSegment.EntitySet;

            Db.OeEntitySetAdapter entitySetAdapter = _dataAdapter.EntitySetAdapters.FindByEntitySetName(entitySet.Name);
            bool isCountSegment = odataUri.Path.LastSegment is CountSegment;

            return(new OeQueryContext(_edmModel, odataUri, entitySet, navigationSegments,
                                      isCountSegment, pageSize, navigationNextLink, _dataAdapter.IsDatabaseNullHighestValue, metadataLevel, entitySetAdapter));
        }
Пример #2
0
        private Expression GetInnerSource(OeNavigationSelectItem navigationItem)
        {
            if (navigationItem.Parent == null)
            {
                throw new InvalidOperationException("Inner source cannot exist for root item");
            }

            Type         clrEntityType         = _edmModel.GetClrType(navigationItem.EdmProperty.DeclaringType);
            PropertyInfo navigationClrProperty = clrEntityType.GetPropertyIgnoreCase(navigationItem.EdmProperty);

            Type itemType          = OeExpressionHelper.GetCollectionItemTypeOrNull(navigationClrProperty.PropertyType) ?? navigationClrProperty.PropertyType;
            var  visitor           = new OeQueryNodeVisitor(_joinBuilder.Visitor, Expression.Parameter(itemType));
            var  expressionBuilder = new OeExpressionBuilder(_joinBuilder, visitor);

            IEdmNavigationProperty navigationProperty = navigationItem.EdmProperty;

            if (navigationItem.EdmProperty.ContainsTarget)
            {
                ModelBuilder.ManyToManyJoinDescription joinDescription = _edmModel.GetManyToManyJoinDescription(navigationProperty);
                navigationProperty = joinDescription.TargetNavigationProperty;
            }
            IEdmEntitySet innerEntitySet = OeEdmClrHelper.GetEntitySet(_edmModel, navigationProperty);
            Expression    innerSource    = OeEnumerableStub.CreateEnumerableStubExpression(itemType, innerEntitySet);

            ExpandedNavigationSelectItem item = navigationItem.NavigationSelectItem;

            innerSource = expressionBuilder.ApplyFilter(innerSource, item.FilterOption);

            long?top = GetTop(navigationItem, item.TopOption);

            if (top == null && item.SkipOption == null)
            {
                return(innerSource);
            }

            OrderByClause orderByClause = item.OrderByOption;

            if (navigationItem.PageSize > 0)
            {
                orderByClause = OeSkipTokenParser.GetUniqueOrderBy(navigationItem.EntitySet, item.OrderByOption, null);
            }

            var        entitySet = (IEdmEntitySet)navigationItem.Parent.EntitySet;
            Expression source    = OeEnumerableStub.CreateEnumerableStubExpression(navigationClrProperty.DeclaringType, entitySet);

            var crossApplyBuilder = new OeCrossApplyBuilder(_edmModel, expressionBuilder);

            return(crossApplyBuilder.Build(source, innerSource, navigationItem.Path, orderByClause, item.SkipOption, top));
        }
        public Uri GetNextPageLinkNavigation(Db.IOeDbEnumerator dbEnumerator, int readCount, long?totalCount, Object value)
        {
            OeEntryFactory entryFactory = dbEnumerator.EntryFactory;
            ExpandedNavigationSelectItem navigationSelectItem = entryFactory.NavigationSelectItem;

            if (navigationSelectItem.GetPageSize() == 0 || readCount == 0 || (totalCount != null && readCount >= totalCount))
            {
                return(null);
            }

            OrderByClause orderByClause = OeSkipTokenParser.GetUniqueOrderBy(entryFactory.EntitySet, navigationSelectItem.OrderByOption, null);

            KeyValuePair <String, Object>[] keys = GetNavigationSkipTokenKeys(entryFactory, orderByClause, value);

            int    restCount = GetRestCountNavigation((int?)navigationSelectItem.TopOption, readCount, totalCount);
            String skipToken = OeSkipTokenParser.GetSkipToken(_queryContext.EdmModel, keys, restCount);

            return(GetNavigationUri(dbEnumerator.ParentEnumerator.EntryFactory, navigationSelectItem, orderByClause, dbEnumerator.ParentEnumerator.Current, skipToken));
        }
Пример #4
0
        internal void AddKeyRecursive(bool notSelected)
        {
            if (!AllSelected)
            {
                foreach (IEdmStructuralProperty keyProperty in EntitySet.EntityType().Key())
                {
                    AddStructuralItem(keyProperty, notSelected);
                }
            }

            if (_navigationSelectItem is ExpandedNavigationSelectItem expanded)
            {
                OrderByClause orderByClause = OeSkipTokenParser.GetUniqueOrderBy(EntitySet, expanded.OrderByOption, null);
                if (expanded.OrderByOption != orderByClause)
                {
                    _navigationSelectItem = new ExpandedNavigationSelectItem(
                        expanded.PathToNavigationProperty,
                        expanded.NavigationSource,
                        expanded.SelectAndExpand,
                        expanded.FilterOption,
                        orderByClause,
                        expanded.TopOption,
                        expanded.SkipOption,
                        expanded.CountOption,
                        expanded.SearchOption,
                        expanded.LevelsOption);
                }
            }

            foreach (OeNavigationSelectItem childNavigationItem in _navigationItems)
            {
                if (!AllSelected && childNavigationItem.Kind == OeNavigationSelectItemKind.NextLink && !childNavigationItem.EdmProperty !.Type.IsCollection())
                {
                    foreach (IEdmStructuralProperty fkeyProperty in childNavigationItem.EdmProperty.DependentProperties())
                    {
                        AddStructuralItem(fkeyProperty, notSelected);
                    }
                }

                childNavigationItem.AddKeyRecursive(notSelected);
            }
        }