Пример #1
0
        /// <summary>
        /// Performs a deep copy of the specified <see cref="EntityType"/>.
        /// </summary>
        /// <param name="entityType">The <see cref="EntityType"/> to deep copy.</param>
        /// <returns>A deep copy of the <see cref="EntityType"/>.</returns>
        private static EntityType Clone(this EntityType entityType)
        {
            var clone = new EntityType(entityType.NamespaceName, entityType.Name)
            {
                BaseType   = entityType.BaseType.NameOrNull(),
                IsAbstract = entityType.IsAbstract,
                IsOpen     = entityType.IsOpen,
            };

            foreach (var property in entityType.Properties)
            {
                clone.Add(property.Clone());
            }

            foreach (var navigationProperty in entityType.NavigationProperties)
            {
                clone.Add(navigationProperty.Clone());
            }

            foreach (var uniqueConstraint in entityType.EdmUniqueConstraints)
            {
                clone.Add(uniqueConstraint.Clone());
            }

            CopyAnnotations(clone, entityType.Annotations);

            return(clone);
        }
        /// <summary>
        /// Converts a potential HasStream annotation to the corresponding test annotation on the <paramref name="entityType"/>.
        /// </summary>
        /// <param name="entityType">EntityType to convert the annotations on.</param>
        private void ConvertHasStreamAnnotation(EntityType entityType)
        {
            ExceptionUtilities.CheckArgumentNotNull(entityType, "entityType");

            var hasStreamAnnotation = entityType.Annotations.OfType<AttributeAnnotation>()
                .Where(ann => ann.Content != null && ann.Content.Name.LocalName == "HasStream").SingleOrDefault();

            if (hasStreamAnnotation != null)
            {
                bool hasStreamValue = bool.Parse(hasStreamAnnotation.Content.Value);
                if (hasStreamValue)
                {
                    entityType.Add(new HasStreamAnnotation());
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Adds and updates existing types in the default model to use Primitive and Complex Collections
        /// </summary>
        /// <param name="model">Model to add fixup to.</param>
        public void Fixup(EntityModelSchema model)
        {
            // Create entityType with all PrimitiveTypes lists
            EntityType allPrimitiveCollectionTypesEntity = new EntityType("AllPrimitiveCollectionTypesEntity");
            allPrimitiveCollectionTypesEntity.Add(new MemberProperty("Key", EdmDataTypes.Int32));
            allPrimitiveCollectionTypesEntity.Properties[0].IsPrimaryKey = true;
            for (int i = 0; i < primitiveTypes.Length; i++)
            {
                DataType t = DataTypes.CollectionType.WithElementDataType(primitiveTypes[i]);
                allPrimitiveCollectionTypesEntity.Add(new MemberProperty("Property" + i, t));
            }

            model.Add(allPrimitiveCollectionTypesEntity);

             // Create a complexType  with all PrimitiveTypes Bags and primitive properties in it
            ComplexType additionalComplexType = new ComplexType("AdditionalComplexType");
            additionalComplexType.Add(new MemberProperty("Bag1", DataTypes.CollectionType.WithElementDataType(EdmDataTypes.DateTime())));
            additionalComplexType.Add(new MemberProperty("Bag3", EdmDataTypes.String()));
            model.Add(additionalComplexType);

            // Create a complexType  with all PrimitiveTypes Bags in it
            ComplexType complexPrimitiveCollectionsType = new ComplexType("ComplexTypePrimitiveCollections");
            for (int i = 0; i < primitiveTypes.Length; i++)
            {
                DataType t = DataTypes.CollectionType.WithElementDataType(primitiveTypes[i]);
                complexPrimitiveCollectionsType.Add(new MemberProperty("Property" + i, t));
            }

            complexPrimitiveCollectionsType.Add(new MemberProperty("ComplexTypeBag", DataTypes.CollectionType.WithElementDataType(DataTypes.ComplexType.WithDefinition(additionalComplexType))));
            model.Add(complexPrimitiveCollectionsType);

            // Add the complexPrimitiveCollectionsType to an entity
            EntityType complexBagsEntity = new EntityType("ComplexBagsEntity");
            complexBagsEntity.Add(new MemberProperty("Key", EdmDataTypes.Int32));
            complexBagsEntity.Properties[0].IsPrimaryKey = true;
            DataType complexDataType = DataTypes.ComplexType.WithDefinition(complexPrimitiveCollectionsType);
            complexBagsEntity.Add(new MemberProperty("CollectionComplexTypePrimitiveCollections", DataTypes.CollectionType.WithElementDataType(complexDataType)));
            complexBagsEntity.Add(new MemberProperty("ComplexTypePrimitiveCollections", complexDataType));

            model.Add(complexBagsEntity);

            int numberOfComplexCollections = 0;
            
            // Update existing model so that every 3rd complexType is a Collection of ComplexTypes
            foreach (EntityType t in model.EntityTypes)
            {
                foreach (MemberProperty complexProperty in t.Properties.Where(p => p.PropertyType is ComplexDataType).ToList())
                {
                    // Remove existing one
                    t.Properties.Remove(complexProperty);

                    // Add new one 
                    t.Properties.Add(new MemberProperty(complexProperty.Name + "Collection", DataTypes.CollectionType.WithElementDataType(complexProperty.PropertyType)));
                    numberOfComplexCollections++;

                    if (numberOfComplexCollections > 4)
                    {
                        break;
                    }
                }

                if (numberOfComplexCollections > 4)
                {
                    break;
                }
            }

            new ResolveReferencesFixup().Fixup(model);

            // ReApply the previously setup namespace on to the new types
            new ApplyDefaultNamespaceFixup(model.EntityTypes.First().NamespaceName).Fixup(model);
            new AddDefaultContainerFixup().Fixup(model);
            new SetDefaultCollectionTypesFixup().Fixup(model);
        }
        private EntityType ConvertToTaupoEntityType(IEdmEntityType edmEntityType)
        {
            var taupoEntityType = new EntityType(edmEntityType.Namespace, edmEntityType.Name)
            {
                IsAbstract = edmEntityType.IsAbstract,
                IsOpen = edmEntityType.IsOpen,
            };

            if (edmEntityType.BaseType != null)
            {
                taupoEntityType.BaseType = new EntityTypeReference(edmEntityType.BaseEntityType().Namespace, edmEntityType.BaseEntityType().Name);
            }

            foreach (var edmProperty in edmEntityType.DeclaredStructuralProperties())
            {
                var taupoProperty = this.ConvertToTaupoProperty(edmProperty);
                taupoProperty.IsPrimaryKey = edmEntityType.Key().Contains(edmProperty);
                taupoEntityType.Add(taupoProperty);
            }

            this.ConvertAnnotationsIntoTaupo(edmEntityType, taupoEntityType);
            return taupoEntityType;
        }