예제 #1
0
        /// <summary>
        /// The factory method for constructing the EntityContainer object.
        /// </summary>
        /// <param name="name">The name of the entity container to be created.</param>
        /// <param name="dataSpace">DataSpace in which this entity container belongs to.</param>
        /// <param name="entitySets">Entity sets that will be included in the new container. Can be null.</param>
        /// <param name="functionImports">Functions that will be included in the new container. Can be null.</param>
        /// <param name="metadataProperties">Metadata properties to be associated with the instance.</param>
        /// <returns>The EntityContainer object.</returns>
        /// <exception cref="T:System.ArgumentException">Thrown if the name argument is null or empty string.</exception>
        /// <remarks>The newly created EntityContainer will be read only.</remarks>
        public static EntityContainer Create(
            string name,
            DataSpace dataSpace,
            IEnumerable <EntitySetBase> entitySets,
            IEnumerable <EdmFunction> functionImports,
            IEnumerable <MetadataProperty> metadataProperties)
        {
            Check.NotEmpty(name, nameof(name));
            EntityContainer entityContainer = new EntityContainer(name, dataSpace);

            if (entitySets != null)
            {
                foreach (EntitySetBase entitySet in entitySets)
                {
                    entityContainer.AddEntitySetBase(entitySet);
                }
            }
            if (functionImports != null)
            {
                foreach (EdmFunction functionImport in functionImports)
                {
                    if (!functionImport.IsFunctionImport)
                    {
                        throw new ArgumentException(Strings.OnlyFunctionImportsCanBeAddedToEntityContainer((object)functionImport.Name));
                    }
                    entityContainer.AddFunctionImport(functionImport);
                }
            }
            if (metadataProperties != null)
            {
                entityContainer.AddMetadataProperties(metadataProperties.ToList <MetadataProperty>());
            }
            entityContainer.SetReadOnly();
            return(entityContainer);
        }
        public void Cannot_add_entity_set_to_readonly_container()
        {
            var entityContainer = new EntityContainer("Container", DataSpace.CSpace);
            var entityType      = new EntityType("E", "N", DataSpace.CSpace);
            var typeUsage       = TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));
            var entitySet       = EntitySet.Create("S", "dbo", "T", "Q", entityType, new[] { new MetadataProperty("P", typeUsage, "V") });

            entityContainer.SetReadOnly();

            Assert.Equal(
                Resources.Strings.OperationOnReadOnlyItem,
                Assert.Throws <InvalidOperationException>(() => entityContainer.AddEntitySetBase(entitySet)).Message);
        }
        public void Cannot_add_function_to_readonly_container()
        {
            var container = new EntityContainer("container", DataSpace.CSpace);

            container.SetReadOnly();

            var function = new EdmFunction(
                "foo",
                "bar",
                DataSpace.CSpace,
                new EdmFunctionPayload()
            {
                IsFunctionImport = false
            });

            Assert.Equal(
                Resources.Strings.OperationOnReadOnlyItem,
                Assert.Throws <InvalidOperationException>(() => container.AddFunctionImport(function)).Message);
        }
예제 #4
0
        /// <summary>
        /// The factory method for constructing the EntityContainer object.
        /// </summary>
        /// <param name="name">The name of the entity container to be created.</param>
        /// <param name="dataSpace">DataSpace in which this entity container belongs to.</param>
        /// <param name="entitySets">Entity sets that will be included in the new container. Can be null.</param>
        /// <param name="functionImports">Functions that will be included in the new container. Can be null.</param>
        /// <param name="metadataProperties">Metadata properties to be associated with the instance.</param>
        /// <returns>The EntityContainer object.</returns>
        /// <exception cref="System.ArgumentException">Thrown if the name argument is null or empty string.</exception>
        /// <remarks>The newly created EntityContainer will be read only.</remarks>
        public static EntityContainer Create(
            string name, DataSpace dataSpace, IEnumerable<EntitySetBase> entitySets,
            IEnumerable<EdmFunction> functionImports, IEnumerable<MetadataProperty> metadataProperties)
        {
            Check.NotEmpty(name, "name");

            var entityContainer = new EntityContainer(name, dataSpace);

            if (entitySets != null)
            {
                foreach (var entitySet in entitySets)
                {
                    entityContainer.AddEntitySetBase(entitySet);
                }
            }

            if (functionImports != null)
            {
                foreach (var function in functionImports)
                {
                    if (!function.IsFunctionImport)
                    {
                        throw new ArgumentException(Strings.OnlyFunctionImportsCanBeAddedToEntityContainer(function.Name));
                    }
                    entityContainer.AddFunctionImport(function);
                }
            }

            if (metadataProperties != null)
            {
                entityContainer.AddMetadataProperties(metadataProperties.ToList());
            }

            entityContainer.SetReadOnly();

            return entityContainer;
        }
        public void Cannot_add_entity_set_to_readonly_container()
        {
            var entityContainer = new EntityContainer("Container", DataSpace.CSpace);
            var entityType = new EntityType("E", "N", DataSpace.CSpace);
            var typeUsage = TypeUsage.CreateDefaultTypeUsage(PrimitiveType.GetEdmPrimitiveType(PrimitiveTypeKind.String));
            var entitySet = EntitySet.Create("S", "dbo", "T", "Q", entityType, new[] { new MetadataProperty("P", typeUsage, "V") });

            entityContainer.SetReadOnly();

            Assert.Equal(
                Resources.Strings.OperationOnReadOnlyItem,
                Assert.Throws<InvalidOperationException>(() => entityContainer.AddEntitySetBase(entitySet)).Message);
        }
        public void Cannot_add_function_to_readonly_container()
        {
            var container = new EntityContainer("container", DataSpace.CSpace);
            container.SetReadOnly();

            var function = new EdmFunction(
                "foo",
                "bar",
                DataSpace.CSpace,
                new EdmFunctionPayload()
                {
                    IsFunctionImport = false
                });

            Assert.Equal(
                Resources.Strings.OperationOnReadOnlyItem,
                Assert.Throws<InvalidOperationException>(() => container.AddFunctionImport(function)).Message);
        }