public EntitySetConfiguration(ODataModelBuilder modelBuilder, EntityTypeConfiguration entityType, string name)
        {
            if (modelBuilder == null)
            {
                throw Error.ArgumentNull("modelBuilder");
            }

            if (entityType == null)
            {
                throw Error.ArgumentNull("entityType");
            }

            if (name == null)
            {
                throw Error.ArgumentNull("name");
            }

            _modelBuilder = modelBuilder;
            Name          = name;
            EntityType    = entityType;
            ClrType       = entityType.ClrType;
            _url          = Name;

            _editLinkBuilder = null;
            _readLinkBuilder = null;
            _navigationPropertyLinkBuilders = new Dictionary <NavigationPropertyConfiguration, NavigationLinkBuilder>();
            _entitySetBindings = new Dictionary <NavigationPropertyConfiguration, NavigationPropertyBindingConfiguration>();
        }
        /// <summary>
        /// Configures the ID for the entities from this entity set.
        /// </summary>
        /// <param name="idLinkBuilder">The builder used to generate the ID.</param>
        /// <returns>Returns itself so that multiple calls can be chained.</returns>
        public virtual EntitySetConfiguration HasIdLink(SelfLinkBuilder <string> idLinkBuilder)
        {
            if (idLinkBuilder == null)
            {
                throw Error.ArgumentNull("idLinkBuilder");
            }

            _idLinkBuilder = idLinkBuilder;
            return(this);
        }
        /// <summary>
        /// Configures the read link for the entities from this entity set.
        /// </summary>
        /// <param name="readLinkBuilder">The builder used to generate the read link.</param>
        /// <returns>Returns itself so that multiple calls can be chained.</returns>
        public virtual EntitySetConfiguration HasReadLink(SelfLinkBuilder <Uri> readLinkBuilder)
        {
            if (readLinkBuilder == null)
            {
                throw Error.ArgumentNull("readLinkBuilder");
            }

            _readLinkBuilder = readLinkBuilder;
            return(this);
        }
        /// <summary>
        /// Configures the edit link for the entities from this entity set.
        /// </summary>
        /// <param name="editLinkBuilder">The builder used to generate the edit link.</param>
        /// <returns>Returns itself so that multiple calls can be chained.</returns>
        public virtual EntitySetConfiguration HasEditLink(SelfLinkBuilder <Uri> editLinkBuilder)
        {
            if (editLinkBuilder == null)
            {
                throw Error.ArgumentNull("editLinkBuilder");
            }

            _editLinkBuilder = editLinkBuilder;
            return(this);
        }
示例#5
0
        public void HasReadLink_RoundTrips()
        {
            // Arrange
            SelfLinkBuilder <Uri> readLinkBuilder = new SelfLinkBuilder <Uri>((ctxt) => null, followsConventions: true);

            // Act
            _entityset.HasReadLink(readLinkBuilder);

            // Assert
            Assert.Equal(readLinkBuilder, _entityset.GetReadLink());
        }
示例#6
0
        public void HasIdLink_RoundTrips()
        {
            // Arrange
            SelfLinkBuilder <string> idLinkBuilder = new SelfLinkBuilder <string>((ctxt) => null, followsConventions: true);

            // Act
            _entityset.HasIdLink(idLinkBuilder);

            // Assert
            Assert.Equal(idLinkBuilder, _entityset.GetIdLink());
        }
        /// <summary>
        /// Constructs an instance of an <see cref="EntitySetLinkBuilderAnnotation" /> from an <see cref="EntitySetConfiguration" />.
        /// </summary>
        public EntitySetLinkBuilderAnnotation(EntitySetConfiguration entitySet)
        {
            if (entitySet == null)
            {
                throw Error.ArgumentNull("entitySet");
            }

            _entitySetName       = entitySet.Name;
            _feedSelfLinkBuilder = entitySet.GetFeedSelfLink();
            _idLinkBuilder       = entitySet.GetIdLink();
            _editLinkBuilder     = entitySet.GetEditLink();
            _readLinkBuilder     = entitySet.GetReadLink();
        }
        public EntitySetLinkBuilderAnnotation(EntitySetConfiguration entitySet)
        {
            if (entitySet == null)
            {
                throw Error.ArgumentNull("entitySet");
            }

            _entitySet           = entitySet;
            _feedSelfLinkBuilder = entitySet.GetFeedSelfLink();
            _idLinkBuilder       = entitySet.GetIdLink();

            _editLinkBuilder = entitySet.GetEditLink();
            _readLinkBuilder = entitySet.GetReadLink();
            _navigationPropertyLinkBuilderLookup = new Dictionary <IEdmNavigationProperty, NavigationLinkBuilder>();
        }
        /// <summary>
        /// Constructs an instance of an <see cref="EntitySetLinkBuilderAnnotation" />.
        /// <remarks>Every parameter must be non-null.</remarks>
        /// </summary>
        public EntitySetLinkBuilderAnnotation(
            IEdmEntitySet entitySet,
            Func <FeedContext, Uri> feedSelfLinkBuilder,
            SelfLinkBuilder <string> idLinkBuilder,
            SelfLinkBuilder <Uri> editLinkBuilder,
            SelfLinkBuilder <Uri> readLinkBuilder)
        {
            if (entitySet == null)
            {
                throw Error.ArgumentNull("entitySet");
            }

            _entitySetName       = entitySet.Name;
            _feedSelfLinkBuilder = feedSelfLinkBuilder;
            _idLinkBuilder       = idLinkBuilder;
            _editLinkBuilder     = editLinkBuilder;
            _readLinkBuilder     = readLinkBuilder;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="EntitySetLinkBuilderAnnotation"/> class.
        /// </summary>
        /// <param name="entitySet">The entity set for which the link builder is being constructed.</param>
        /// <param name="model">The EDM model that this entity set belongs to.</param>
        /// <remarks>This constructor creates a link builder that generates URL's that follow OData conventions for the given entity set.</remarks>
        public EntitySetLinkBuilderAnnotation(IEdmEntitySet entitySet, IEdmModel model)
        {
            if (entitySet == null)
            {
                throw Error.ArgumentNull("entitySet");
            }
            if (model == null)
            {
                throw Error.ArgumentNull("model");
            }

            IEdmEntityType elementType = entitySet.ElementType;
            IEnumerable <IEdmEntityType> derivedTypes = model.FindAllDerivedTypes(elementType).Cast <IEdmEntityType>();
            bool derivedTypesDefineNavigationProperty = false;

            // Add navigation link builders for all navigation properties of entity.
            foreach (IEdmNavigationProperty navigationProperty in elementType.NavigationProperties())
            {
                Func <EntityInstanceContext, IEdmNavigationProperty, Uri> navigationLinkFactory =
                    (entityInstanceContext, navProperty) => entityInstanceContext.GenerateNavigationPropertyLink(navProperty, includeCast: false);
                AddNavigationPropertyLinkBuilder(navigationProperty, new NavigationLinkBuilder(navigationLinkFactory, followsConventions: true));
            }

            // Add navigation link builders for all navigation properties in derived types.
            foreach (IEdmEntityType derivedEntityType in derivedTypes)
            {
                foreach (IEdmNavigationProperty navigationProperty in derivedEntityType.DeclaredNavigationProperties())
                {
                    derivedTypesDefineNavigationProperty = true;
                    Func <EntityInstanceContext, IEdmNavigationProperty, Uri> navigationLinkFactory =
                        (entityInstanceContext, navProperty) => entityInstanceContext.GenerateNavigationPropertyLink(navProperty, includeCast: true);
                    AddNavigationPropertyLinkBuilder(navigationProperty, new NavigationLinkBuilder(navigationLinkFactory, followsConventions: true));
                }
            }

            _entitySetName       = entitySet.Name;
            _feedSelfLinkBuilder = (feedContext) => feedContext.GenerateFeedSelfLink();

            Func <EntityInstanceContext, string> selfLinkFactory =
                (entityInstanceContext) => entityInstanceContext.GenerateSelfLink(includeCast: derivedTypesDefineNavigationProperty);

            _idLinkBuilder = new SelfLinkBuilder <string>(selfLinkFactory, followsConventions: true);
        }