private void CreateStructuralTypeBody(EdmStructuredType type, IStructuralTypeConfiguration config) { foreach (PrimitivePropertyConfiguration prop in config.Properties.OfType<PrimitivePropertyConfiguration>()) { type.AddStructuralProperty( prop.PropertyInfo.Name, GetTypeKind(prop.PropertyInfo.PropertyType), prop.OptionalProperty); } foreach (ComplexPropertyConfiguration prop in config.Properties.OfType<ComplexPropertyConfiguration>()) { IEdmComplexType complexType = _types[prop.RelatedClrType.FullName] as IEdmComplexType; type.AddStructuralProperty( prop.PropertyInfo.Name, new EdmComplexTypeReference(complexType, prop.OptionalProperty)); } }
private IEdmProperty CreateProperty(EdmStructuredType declaringType, ResourceProperty resourceProperty) { IEdmProperty property; List<KeyValuePair<string, object>> annotations = (resourceProperty.CustomAnnotations == null) ? null : resourceProperty.CustomAnnotations.ToList<KeyValuePair<string, object>>(); ODataNullValueBehaviorKind nullValueReadBehaviorKind = ODataNullValueBehaviorKind.Default; if (resourceProperty.IsOfKind(ResourcePropertyKind.Primitive) || resourceProperty.IsOfKind(ResourcePropertyKind.Stream)) { IEdmPrimitiveTypeReference typeReference = MetadataProviderUtils.CreatePrimitiveTypeReference(resourceProperty.ResourceType, annotations); if (resourceProperty.IsOfKind(ResourcePropertyKind.Key)) { if (typeReference.IsNullable) { typeReference = (IEdmPrimitiveTypeReference) typeReference.Clone(false); } nullValueReadBehaviorKind = ODataNullValueBehaviorKind.IgnoreValue; } else if (MetadataProviderUtils.ShouldDisablePrimitivePropertyNullValidation(resourceProperty, typeReference)) { nullValueReadBehaviorKind = ODataNullValueBehaviorKind.DisableValidation; } string andRemoveDefaultValue = MetadataProviderUtils.GetAndRemoveDefaultValue(annotations); EdmConcurrencyMode concurrencyMode = resourceProperty.IsOfKind(ResourcePropertyKind.ETag) ? EdmConcurrencyMode.Fixed : EdmConcurrencyMode.None; property = declaringType.AddStructuralProperty(resourceProperty.Name, typeReference, andRemoveDefaultValue, concurrencyMode); string mimeType = resourceProperty.MimeType; if (!string.IsNullOrEmpty(mimeType)) { this.SetMimeType(property, mimeType); } } else if (resourceProperty.IsOfKind(ResourcePropertyKind.ComplexType)) { IEdmTypeReference reference2 = this.EnsureTypeReference(resourceProperty.ResourceType, annotations); string defaultValue = MetadataProviderUtils.GetAndRemoveDefaultValue(annotations); property = declaringType.AddStructuralProperty(resourceProperty.Name, reference2, defaultValue, EdmConcurrencyMode.None); if (this.metadataProvider.IsV1Provider && !reference2.IsNullable) { nullValueReadBehaviorKind = ODataNullValueBehaviorKind.DisableValidation; } } else if (resourceProperty.IsOfKind(ResourcePropertyKind.Collection)) { string str4 = MetadataProviderUtils.GetAndRemoveDefaultValue(annotations); IEdmTypeReference reference3 = this.EnsureTypeReference(resourceProperty.ResourceType, annotations); property = declaringType.AddStructuralProperty(resourceProperty.Name, reference3, str4, EdmConcurrencyMode.None); } else { if (!resourceProperty.IsOfKind(ResourcePropertyKind.ResourceSetReference) && !resourceProperty.IsOfKind(ResourcePropertyKind.ResourceReference)) { throw new InvalidOperationException(System.Data.Services.Strings.MetadataProviderEdmModel_UnsupportedResourcePropertyKind(resourceProperty.Kind.ToString())); } EdmEntityType type = (EdmEntityType) declaringType; IEdmTypeReference reference4 = resourceProperty.IsOfKind(ResourcePropertyKind.ResourceSetReference) ? this.EnsureEntityPrimitiveOrComplexCollectionTypeReference(resourceProperty.ResourceType, annotations) : this.EnsureTypeReference(resourceProperty.ResourceType, annotations); property = new MetadataProviderEdmNavigationProperty(type, resourceProperty.Name, reference4); type.AddProperty(property); } this.SetNullValueReaderBehavior(property, nullValueReadBehaviorKind); MetadataProviderUtils.ConvertCustomAnnotations(this, annotations, property); return property; }
private void CreateStructuralTypeBody(EdmStructuredType type, IStructuralTypeConfiguration config) { foreach (PropertyConfiguration property in config.Properties) { switch (property.Kind) { case PropertyKind.Primitive: PrimitivePropertyConfiguration primitiveProperty = property as PrimitivePropertyConfiguration; type.AddStructuralProperty( primitiveProperty.PropertyInfo.Name, GetTypeKind(primitiveProperty.PropertyInfo.PropertyType), primitiveProperty.OptionalProperty); break; case PropertyKind.Complex: ComplexPropertyConfiguration complexProperty = property as ComplexPropertyConfiguration; IEdmComplexType complexType = _types[complexProperty.RelatedClrType] as IEdmComplexType; type.AddStructuralProperty( complexProperty.PropertyInfo.Name, new EdmComplexTypeReference(complexType, complexProperty.OptionalProperty)); break; case PropertyKind.Collection: CollectionPropertyConfiguration collectionProperty = property as CollectionPropertyConfiguration; IEdmTypeReference elementTypeReference = null; if (_types.ContainsKey(collectionProperty.ElementType)) { IEdmComplexType elementType = _types[collectionProperty.ElementType] as IEdmComplexType; elementTypeReference = new EdmComplexTypeReference(elementType, false); } else { elementTypeReference = EdmLibHelpers.GetEdmPrimitiveTypeReferenceOrNull(collectionProperty.ElementType); } type.AddStructuralProperty( collectionProperty.PropertyInfo.Name, new EdmCollectionTypeReference( new EdmCollectionType(elementTypeReference), collectionProperty.OptionalProperty)); break; default: break; } } }
private void CreateStructuralTypeBody(EdmStructuredType type, StructuralTypeConfiguration config) { foreach (PropertyConfiguration property in config.Properties) { switch (property.Kind) { case PropertyKind.Primitive: PrimitivePropertyConfiguration primitiveProperty = property as PrimitivePropertyConfiguration; EdmPrimitiveTypeKind typeKind = GetTypeKind(primitiveProperty.PropertyInfo.PropertyType); IEdmTypeReference primitiveTypeReference = EdmCoreModel.Instance.GetPrimitive( typeKind, primitiveProperty.OptionalProperty); var primitiveProp = new EdmStructuralProperty( type, primitiveProperty.PropertyInfo.Name, primitiveTypeReference); type.AddProperty(primitiveProp); // Set Annotation StoreGeneratedPattern if (config.Kind == EdmTypeKind.Entity && primitiveProperty.StoreGeneratedPattern != DatabaseGeneratedOption.None) { _directValueAnnotations.Add( new StoreGeneratedPatternAnnotation(primitiveProp, primitiveProperty.StoreGeneratedPattern)); } break; case PropertyKind.Complex: ComplexPropertyConfiguration complexProperty = property as ComplexPropertyConfiguration; IEdmComplexType complexType = _types[complexProperty.RelatedClrType] as IEdmComplexType; type.AddStructuralProperty( complexProperty.PropertyInfo.Name, new EdmComplexTypeReference(complexType, complexProperty.OptionalProperty)); break; case PropertyKind.Collection: CollectionPropertyConfiguration collectionProperty = property as CollectionPropertyConfiguration; IEdmTypeReference elementTypeReference = null; if (_types.ContainsKey(collectionProperty.ElementType)) { IEdmComplexType elementType = _types[collectionProperty.ElementType] as IEdmComplexType; elementTypeReference = new EdmComplexTypeReference(elementType, false); } else { elementTypeReference = EdmLibHelpers.GetEdmPrimitiveTypeReferenceOrNull(collectionProperty.ElementType); } type.AddStructuralProperty( collectionProperty.PropertyInfo.Name, new EdmCollectionTypeReference( new EdmCollectionType(elementTypeReference), collectionProperty.OptionalProperty)); break; default: break; } } }
private void CreatePrimitiveProperty(PrimitivePropertyConfiguration primitiveProperty, EdmStructuredType type, StructuralTypeConfiguration config, out IEdmProperty edmProperty) { EdmPrimitiveTypeKind typeKind = GetTypeKind(primitiveProperty.PropertyInfo.PropertyType); IEdmTypeReference primitiveTypeReference = EdmCoreModel.Instance.GetPrimitive( typeKind, primitiveProperty.OptionalProperty); // Set concurrency token if is entity type, and concurrency token is true EdmConcurrencyMode concurrencyMode = EdmConcurrencyMode.None; if (config.Kind == EdmTypeKind.Entity && primitiveProperty.ConcurrencyToken) { concurrencyMode = EdmConcurrencyMode.Fixed; } var primitiveProp = new EdmStructuralProperty( type, primitiveProperty.PropertyInfo.Name, primitiveTypeReference, defaultValueString: null, concurrencyMode: concurrencyMode); type.AddProperty(primitiveProp); edmProperty = primitiveProp; // Set Annotation StoreGeneratedPattern if (config.Kind == EdmTypeKind.Entity && primitiveProperty.StoreGeneratedPattern != DatabaseGeneratedOption.None) { _directValueAnnotations.Add( new StoreGeneratedPatternAnnotation(primitiveProp, primitiveProperty.StoreGeneratedPattern)); } }