コード例 #1
0
        private static IEdmTypeReference AddLengthConfigInPrimitiveTypeReference(
            LengthPropertyConfiguration lengthProperty,
            IEdmTypeReference primitiveTypeReference)
        {
            if (lengthProperty.MaxLength.HasValue)
            {
                if (primitiveTypeReference is EdmStringTypeReference)
                {
                    return(new EdmStringTypeReference(
                               (IEdmPrimitiveType)primitiveTypeReference.Definition,
                               primitiveTypeReference.IsNullable,
                               false,
                               lengthProperty.MaxLength,
                               true));
                }
                if (primitiveTypeReference is EdmBinaryTypeReference)
                {
                    return(new EdmBinaryTypeReference(
                               (IEdmPrimitiveType)primitiveTypeReference.Definition,
                               primitiveTypeReference.IsNullable,
                               false,
                               lengthProperty.MaxLength));
                }
            }

            return(primitiveTypeReference);
        }
コード例 #2
0
        private LengthPropertyConfiguration Cloning_a_length_property_configuration_clones_its_property_information(
            LengthPropertyConfiguration configuration)
        {
            configuration.IsFixedLength = true;
            configuration.IsMaxLength   = true;
            configuration.MaxLength     = 77;

            var clone = (LengthPropertyConfiguration)
                        Cloning_a_primitive_property_configuration_clones_its_property_information_implementation(configuration);

            Assert.True(clone.IsFixedLength.Value);
            Assert.True(clone.IsMaxLength.Value);
            Assert.Equal(77, clone.MaxLength);

            return(clone);
        }
コード例 #3
0
        /// <summary>
        /// Configures string or binary propertie's maxLength.
        /// </summary>
        /// <param name="edmProperty">The key property.</param>
        /// <param name="structuralTypeConfiguration">The edm type being configured.</param>
        /// <param name="attribute">The <see cref="Attribute"/> found on the property.</param>
        /// <param name="model">The ODataConventionModelBuilder used to build the model.</param>
        public override void Apply(StructuralPropertyConfiguration edmProperty,
            StructuralTypeConfiguration structuralTypeConfiguration,
            Attribute attribute,
            ODataConventionModelBuilder model)
        {
            if (edmProperty == null)
            {
                throw Error.ArgumentNull("edmProperty");
            }

            MaxLengthAttribute maxLengthAttribute = attribute as MaxLengthAttribute;
            LengthPropertyConfiguration lengthProperty = edmProperty as LengthPropertyConfiguration;
            if (lengthProperty != null && maxLengthAttribute != null)
            {
                lengthProperty.MaxLength = maxLengthAttribute.Length;
            }
        }
コード例 #4
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 = (PrimitivePropertyConfiguration)property;
                    EdmPrimitiveTypeKind           typeKind          = primitiveProperty.TargetEdmTypeKind ??
                                                                       GetTypeKind(primitiveProperty.PropertyInfo.PropertyType);
                    IEdmTypeReference primitiveTypeReference = EdmCoreModel.Instance.GetPrimitive(
                        typeKind,
                        primitiveProperty.NullableProperty);

                    if (typeKind == EdmPrimitiveTypeKind.Decimal)
                    {
                        DecimalPropertyConfiguration decimalProperty =
                            primitiveProperty as DecimalPropertyConfiguration;
                        if (decimalProperty.Precision.HasValue || decimalProperty.Scale.HasValue)
                        {
                            primitiveTypeReference = new EdmDecimalTypeReference(
                                (IEdmPrimitiveType)primitiveTypeReference.Definition,
                                primitiveTypeReference.IsNullable,
                                decimalProperty.Precision,
                                decimalProperty.Scale.HasValue ? decimalProperty.Scale : 0);
                        }
                    }
                    else if (EdmLibHelpers.HasPrecision(typeKind))
                    {
                        PrecisionPropertyConfiguration precisionProperty =
                            primitiveProperty as PrecisionPropertyConfiguration;
                        primitiveTypeReference = AddPrecisionConfigInPrimitiveTypeReference(
                            precisionProperty,
                            primitiveTypeReference);
                    }
                    else if (EdmLibHelpers.HasLength(typeKind))
                    {
                        LengthPropertyConfiguration lengthProperty =
                            primitiveProperty as LengthPropertyConfiguration;
                        primitiveTypeReference = AddLengthConfigInPrimitiveTypeReference(
                            lengthProperty,
                            primitiveTypeReference);
                    }
                    edmProperty = type.AddStructuralProperty(
                        primitiveProperty.Name,
                        primitiveTypeReference,
                        defaultValue: primitiveProperty.DefaultValueString);
                    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.NullableProperty));
                    break;

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

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

                default:
                    break;
                }

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

                    if (property.IsRestricted)
                    {
                        _propertiesRestrictions[edmProperty] = new QueryableRestrictions(property);
                    }

                    //if (property.QueryConfiguration.ModelBoundQuerySettings != null)
                    //{
                    //    _propertiesQuerySettings.Add(edmProperty, property.QueryConfiguration.ModelBoundQuerySettings);
                    //}
                }
            }
        }
コード例 #5
0
 internal LengthColumnConfiguration(LengthPropertyConfiguration configuration)
     : base(configuration)
 {
 }