/// <summary> /// Adds a stream reference property to the <paramref name="entityType"/>. /// Returns the modified entity type for composability. /// </summary> /// <param name="entityType">The <see cref="EntityType"/> to add the navigation property to.</param> /// <param name="propertyName">The name of the property to add.</param> /// <returns>The <paramref name="entityType"/> instance after adding the stream reference property to it.</returns> public static EntityType StreamProperty(this EntityType entityType, string propertyName) { ExceptionUtilities.CheckArgumentNotNull(entityType, "entityType"); ExceptionUtilities.CheckArgumentNotNull(propertyName, "propertyName"); // add the named stream property to the generated entity type entityType.Add(new MemberProperty(propertyName, EdmDataTypes.Stream)); return(entityType); }
/// <summary> /// Adds a (primitive, complex or collection) property to the <paramref name="entityType"/>. /// Returns the modified entity type for composability. /// </summary> /// <param name="entityType">The <see cref="EntityType"/> to add the new property to.</param> /// <param name="propertyName">The name of the property to add.</param> /// <param name="type">The data type of the property.</param> /// <param name="isETagProperty">A flag indicating whether the property is an ETag property (default = false).</param> /// <returns>The <paramref name="entityType"/> instance after adding the property to it.</returns> public static EntityType KeyProperty(this EntityType entityType, string propertyName, DataType type, bool isETagProperty = false) { ExceptionUtilities.CheckArgumentNotNull(entityType, "entityType"); ExceptionUtilities.CheckArgumentNotNull(propertyName, "propertyName"); ExceptionUtilities.CheckArgumentNotNull(type, "type"); MemberProperty property = new MemberProperty(propertyName, type); property.IsPrimaryKey = true; entityType.Add(property); return(entityType); }
/// <summary> /// Adds a navigation property to the <paramref name="entityType"/>. This method creates an association type /// in order to add the navigation property. /// Returns the modified entity type for composability. /// </summary> /// <param name="entityType">The <see cref="EntityType"/> to add the navigation property to.</param> /// <param name="propertyName">The name of the property to add.</param> /// <param name="otherEndType">The type of the other end of the navigation property.</param> /// <param name="isSingletonRelationship">true if the navigation property is of singleton cardinality; false for a cardinality many. Default is false.</param> /// <returns>The <paramref name="entityType"/> instance after adding the navigation property to it.</returns> public static EntityType NavigationProperty(this EntityType entityType, string propertyName, EntityType otherEndType, bool isSingletonRelationship = false) { ExceptionUtilities.CheckArgumentNotNull(entityType, "entityType"); ExceptionUtilities.CheckArgumentNotNull(propertyName, "propertyName"); EntityModelSchema model = entityType.Model(); // create the association type between the two entity types AssociationType associationType = model.AssociationType(entityType, otherEndType, isSingletonRelationship); // add the navigation property to the generated entity type entityType.Add(new NavigationProperty(propertyName, associationType, associationType.Ends[0], associationType.Ends[1])); return(entityType); }
/// <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()); } } }
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); }
/// <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); }
/// <summary> /// Marks the <paramref name="entityType"/> as MLE, with default stream. /// </summary> /// <param name="entityType">The entity type to mark as MLE.</param> /// <returns>The <paramref name="entityType"/> once it is marked as MLE.</returns> public static EntityType DefaultStream(this EntityType entityType) { ExceptionUtilities.CheckArgumentNotNull(entityType, "entityType"); entityType.Add(new HasStreamAnnotation()); return(entityType); }