コード例 #1
0
        public override void Handle(ExpandedNavigationSelectItem item)
        {
            var edmNavigationProperty = item.PathToNavigationProperty.LastSegment.As <NavigationPropertySegment>().NavigationProperty;
            INavigationProperty navigationProperty;

            if (!this.resultingDtoBuilder.EntityType.TryGetNavigationProperty(edmNavigationProperty.Name, out navigationProperty))
            {
                throw new KeyNotFoundException("Navigation property " + edmNavigationProperty.Name + " not found.");
            }

            var childEntities = this.entityReader.ReadEntitiesFromRelativePath(this.modelContext, this.sourceEntity, item.PathToNavigationProperty);

            if (item.SelectAndExpand == null || item.SelectAndExpand.AllSelected)
            {
                this.resultingDtoBuilder.ApplyNavigationProperty(navigationProperty, childEntities, this.defaultChildDtoInitializer);
            }
            else
            {
                // handle the select/expand clause of the child entity
                this.resultingDtoBuilder.ApplyNavigationProperty(
                    navigationProperty,
                    childEntities,
                    (childDtoBuilder, childEntity) =>
                {
                    var childHandler = new DefaultSelectItemHandler(
                        this.entityReader,
                        this.modelContext,
                        childEntity,
                        childDtoBuilder,
                        this.defaultChildDtoInitializer);

                    item.SelectAndExpand.SelectedItems.ForEach(i => i.HandleWith(childHandler));
                });
            }
        }
コード例 #2
0
        private IEnumerable <ODataEntityDto> SerializeEntities(
            IBindableModelContext context,
            IEnumerable <IEntity> entities,
            IEntityType entityType,
            SelectExpandClause selectExpandClause)
        {
            foreach (var entity in entities)
            {
                var dtoBuilder = this.dtoBuilderFactory.Create(entityType);
                if (selectExpandClause == null || selectExpandClause.AllSelected)
                {
                    SelectAllProperties(dtoBuilder, entity);
                }
                else
                {
                    var selectItemHandler = new DefaultSelectItemHandler(this.entityReader, context, entity, dtoBuilder, SelectAllProperties);
                    selectItemHandler.HandleAll(selectExpandClause.SelectedItems);
                }

                yield return(dtoBuilder.DtoUnderConstruction);
            }
        }