Beispiel #1
0
        private IEdmProperty CreateStructuralTypeEnumPropertyBody(EdmStructuredType type, StructuralTypeConfiguration config, EnumPropertyConfiguration enumProperty)
        {
            Type     enumPropertyType = TypeHelper.GetUnderlyingTypeOrSelf(enumProperty.RelatedClrType);
            IEdmType edmType          = GetEdmType(enumPropertyType);

            if (edmType == null)
            {
                throw Error.InvalidOperation(SRResources.EnumTypeDoesNotExist, enumPropertyType.Name);
            }

            IEdmEnumType      enumType          = (IEdmEnumType)edmType;
            IEdmTypeReference enumTypeReference = new EdmEnumTypeReference(enumType, enumProperty.OptionalProperty);

            // Set concurrency token if is entity type, and concurrency token is true
            EdmConcurrencyMode enumConcurrencyMode = EdmConcurrencyMode.None;

            if (config.Kind == EdmTypeKind.Entity && enumProperty.ConcurrencyToken)
            {
                enumConcurrencyMode = EdmConcurrencyMode.Fixed;
            }

            return(type.AddStructuralProperty(
                       enumProperty.Name,
                       enumTypeReference,
                       defaultValue: null,
                       concurrencyMode: enumConcurrencyMode));
        }
Beispiel #2
0
        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));
            }
        }
Beispiel #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MetadataProviderEdmStructuralProperty"/> class.
 /// </summary>
 /// <param name="declaringType">The type that declares this property.</param>
 /// <param name="resourceProperty">The resource-property this edm property is based on.</param>
 /// <param name="type">The type of the property.</param>
 /// <param name="defaultValue">The default value of this property.</param>
 /// <param name="concurrencyMode">The concurrency mode of this property.</param>
 public MetadataProviderEdmStructuralProperty(
     IEdmStructuredType declaringType,
     ResourceProperty resourceProperty,
     IEdmTypeReference type,
     string defaultValue,
     EdmConcurrencyMode concurrencyMode)
     : base(declaringType, resourceProperty.Name, type, defaultValue, concurrencyMode)
 {
     this.ResourceProperty = resourceProperty;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="MetadataProviderEdmStructuralProperty"/> class.
 /// </summary>
 /// <param name="declaringType">The type that declares this property.</param>
 /// <param name="resourceProperty">The resource-property this edm property is based on.</param>
 /// <param name="type">The type of the property.</param>
 /// <param name="defaultValue">The default value of this property.</param>
 /// <param name="concurrencyMode">The concurrency mode of this property.</param>
 public MetadataProviderEdmStructuralProperty(
     IEdmStructuredType declaringType,
     ResourceProperty resourceProperty,
     IEdmTypeReference type, 
     string defaultValue,
     EdmConcurrencyMode concurrencyMode)
     : base(declaringType, resourceProperty.Name, type, defaultValue, concurrencyMode)
 {
     this.ResourceProperty = resourceProperty;
 }
        private static string ConcurrencyModeAsXml(EdmConcurrencyMode mode)
        {
            switch (mode)
            {
            case EdmConcurrencyMode.Fixed:
                return(CsdlConstants.Value_Fixed);

            case EdmConcurrencyMode.None:
                return(CsdlConstants.Value_None);

            default:
                throw new InvalidOperationException(Strings.UnknownEnumVal_ConcurrencyMode(mode.ToString()));
            }
        }
Beispiel #6
0
        /// <summary>Adds a new structural property.</summary>
        /// <param name="structuredType">The type to add the property to.</param>
        /// <param name="name">The name of the property to add.</param>
        /// <param name="concurrencyMode">The concurrency mode of the property.</param>
        /// <param name="propertyTypeReference">The type of the property to add.</param>
        /// <param name="propertyInfo">If this is a CLR property, the <see cref="PropertyInfo"/> for the property, or null otherwise.</param>
        /// <returns>The newly created and added property.</returns>
        private IEdmStructuralProperty AddStructuralProperty(
            IEdmStructuredType structuredType,
            string name,
            EdmConcurrencyMode concurrencyMode,
            IEdmTypeReference propertyTypeReference)
        {
            EdmStructuralProperty property = new EdmStructuralProperty(
                structuredType,
                name,
                propertyTypeReference,
                /*defaultValue*/ null,
                concurrencyMode);

            ((EdmStructuredType)structuredType).AddProperty(property);

            return(property);
        }
        private static string ConcurrencyModeAsXml(EdmConcurrencyMode mode)
        {
            EdmConcurrencyMode edmConcurrencyMode = mode;

            switch (edmConcurrencyMode)
            {
            case EdmConcurrencyMode.None:
            {
                return("None");
            }

            case EdmConcurrencyMode.Fixed:
            {
                return("Fixed");
            }
            }
            throw new InvalidOperationException(Strings.UnknownEnumVal_ConcurrencyMode(mode.ToString()));
        }
Beispiel #8
0
 public EdmStructuralProperty(IEdmStructuredType declaringType, string name, IEdmTypeReference type, string defaultValueString, EdmConcurrencyMode concurrencyMode)
     : base(declaringType, name, type)
 {
     this.defaultValueString = defaultValueString;
     this.concurrencyMode    = concurrencyMode;
 }
Beispiel #9
0
        /// <summary>Adds a key property to the specified <paramref name="structuredType"/>.</summary>
        /// <param name="structuredType">The type to add the property to.</param>
        /// <param name="name">The name of the property to add.</param>
        /// <param name="propertyType">The CLR type of the property to add. This can be only a primitive type.</param>
        /// <param name="concurrencyMode">Concurrency mode of the property to add.</param>
        private IEdmStructuralProperty AddPrimitiveProperty(IEdmStructuredType structuredType, string name, Type propertyType, EdmConcurrencyMode concurrencyMode)
        {
            PropertyInfo propertyInfo = null;

            if (propertyType == null)
            {
                //TODO: Fix this so GetInstanceType works
                //propertyInfo = structuredType.GetInstanceType(this).GetProperty(name);
                propertyType = propertyInfo != null ? propertyInfo.PropertyType : null;
            }

            IEdmPrimitiveTypeReference typeReference = MetadataUtils.GetPrimitiveTypeReference(propertyType);

            return(AddStructuralProperty(structuredType, name, concurrencyMode, typeReference));
        }
Beispiel #10
0
        private void CreateStructuralTypeBody(EdmStructuredType type, StructuralTypeConfiguration config)
        {
            foreach (PropertyConfiguration property in config.Properties)
            {
                IEdmProperty edmProperty = null;

                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);

                    // 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;
                    }
                    edmProperty = type.AddStructuralProperty(
                        primitiveProperty.Name,
                        primitiveTypeReference,
                        defaultValue: null,
                        concurrencyMode: concurrencyMode);
                    break;

                case PropertyKind.Complex:
                    ComplexPropertyConfiguration complexProperty = property as ComplexPropertyConfiguration;
                    IEdmComplexType complexType = GetEdmType(complexProperty.RelatedClrType) as IEdmComplexType;

                    edmProperty = type.AddStructuralProperty(
                        complexProperty.Name,
                        new EdmComplexTypeReference(complexType, complexProperty.OptionalProperty));
                    break;

                case PropertyKind.Collection:
                    edmProperty = CreateStructuralTypeCollectionPropertyBody(type, (CollectionPropertyConfiguration)property);
                    break;

                case PropertyKind.Enum:
                    edmProperty = CreateStructuralTypeEnumPropertyBody(type, config, (EnumPropertyConfiguration)property);
                    break;

                default:
                    break;
                }

                if (edmProperty != null)
                {
                    if (property.PropertyInfo != null)
                    {
                        _properties[property.PropertyInfo] = edmProperty;
                    }

                    if (property.IsRestricted)
                    {
                        _propertiesRestrictions[edmProperty] = new QueryableRestrictions(property);
                    }
                }
            }
        }
Beispiel #11
0
        /// <summary>
        /// Adds a (primitive, complex or collection) property to the <paramref name="structuralType"/>.
        /// Returns the modified structural type for composability.
        /// </summary>
        /// <typeparam name="T">The type of the structural type to add the property to.</typeparam>
        /// <param name="structuralType">The structural type 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">true if the property is an ETag property; otherwise false (default).</param>
        /// <returns>The <paramref name="structuralType"/> instance after adding the property to it.</returns>
        public static T Property <T>(this T structuralType, string propertyName, IEdmTypeReference type, EdmConcurrencyMode isETagProperty = EdmConcurrencyMode.None)
            where T : EdmStructuredType
        {
            ExceptionUtilities.CheckArgumentNotNull(structuralType, "structuralType");
            ExceptionUtilities.CheckArgumentNotNull(propertyName, "propertyName");
            ExceptionUtilities.CheckArgumentNotNull(type, "type");

            structuralType.AddStructuralProperty(propertyName, type, string.Empty, isETagProperty);
            return(structuralType);
        }
Beispiel #12
0
        /// <summary>
        /// Creates and adds a structural property to this type.
        /// </summary>
        /// <param name="name">Name of the property.</param>
        /// <param name="type">Type of the property.</param>
        /// <param name="defaultValue">The default value of this property.</param>
        /// <param name="concurrencyMode">The concurrency mode of this property.</param>
        /// <returns>Created structural property.</returns>
        public EdmStructuralProperty AddStructuralProperty(string name, IEdmTypeReference type, string defaultValue, EdmConcurrencyMode concurrencyMode)
        {
            EdmStructuralProperty property = new EdmStructuralProperty(this, name, type, defaultValue, concurrencyMode);

            this.AddProperty(property);
            return(property);
        }
Beispiel #13
0
 /// <summary>
 /// Creates and adds a structural property to this type.
 /// </summary>
 /// <param name="name">Name of the property.</param>
 /// <param name="type">Type of the property.</param>
 /// <param name="defaultValue">The default value of this property.</param>
 /// <param name="concurrencyMode">The concurrency mode of this property.</param>
 /// <returns>Created structural property.</returns>
 public EdmStructuralProperty AddStructuralProperty(string name, IEdmTypeReference type, string defaultValue, EdmConcurrencyMode concurrencyMode)
 {
     EdmStructuralProperty property = new EdmStructuralProperty(this, name, type, defaultValue, concurrencyMode);
     this.AddProperty(property);
     return property;
 }
Beispiel #14
0
        /// <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="concurrencyMode">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 EdmEntityType KeyProperty(this EdmEntityType entityType, string propertyName, IEdmTypeReference type, EdmConcurrencyMode concurrencyMode = EdmConcurrencyMode.None)
        {
            ExceptionUtilities.CheckArgumentNotNull(entityType, "entityType");
            ExceptionUtilities.CheckArgumentNotNull(propertyName, "propertyName");
            ExceptionUtilities.CheckArgumentNotNull(type, "type");

            var property = entityType.AddStructuralProperty(propertyName, type, string.Empty, concurrencyMode);

            entityType.AddKeys(property);

            return(entityType);
        }
Beispiel #15
0
        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);
        }
 public EdmStructuralProperty(IEdmStructuredType declaringType, string name, IEdmTypeReference type, string defaultValueString, EdmConcurrencyMode concurrencyMode)
     : base(declaringType, name, type)
 {
     this.defaultValueString = defaultValueString;
     this.concurrencyMode = concurrencyMode;
 }
        /// <summary>Adds a new structural property.</summary>
        /// <param name="structuredType">The type to add the property to.</param>
        /// <param name="name">The name of the property to add.</param>
        /// <param name="concurrencyMode">The concurrency mode of the property.</param>
        /// <param name="propertyTypeReference">The type of the property to add.</param>
        /// <param name="propertyInfo">If this is a CLR property, the <see cref="PropertyInfo"/> for the property, or null otherwise.</param>
        /// <returns>The newly created and added property.</returns>
        private IEdmStructuralProperty AddStructuralProperty(
            IEdmStructuredType structuredType,
            string name,
            EdmConcurrencyMode concurrencyMode,
            IEdmTypeReference propertyTypeReference)
        {
            EdmStructuralProperty property = new EdmStructuralProperty(
                structuredType,
                name,
                propertyTypeReference,
                /*defaultValue*/null,
                concurrencyMode);

            ((EdmStructuredType)structuredType).AddProperty(property);

            return property;
        }
        /// <summary>Adds a key property to the specified <paramref name="structuredType"/>.</summary>
        /// <param name="structuredType">The type to add the property to.</param>
        /// <param name="name">The name of the property to add.</param>
        /// <param name="propertyType">The CLR type of the property to add. This can be only a primitive type.</param>
        /// <param name="concurrencyMode">Concurrency mode of the property to add.</param>
        private IEdmStructuralProperty AddPrimitiveProperty(IEdmStructuredType structuredType, string name, Type propertyType, EdmConcurrencyMode concurrencyMode)
        {
            PropertyInfo propertyInfo = null;
            if (propertyType == null)
            {
                //TODO: Fix this so GetInstanceType works
                //propertyInfo = structuredType.GetInstanceType(this).GetProperty(name);
                propertyType = propertyInfo != null ? propertyInfo.PropertyType : null;
            }

            IEdmPrimitiveTypeReference typeReference = MetadataUtils.GetPrimitiveTypeReference(propertyType);
            return AddStructuralProperty(structuredType, name, concurrencyMode, typeReference);
        }