示例#1
0
        public void Enum_should_create_property_type()
        {
            var property = EdmProperty.Enum("P", new EnumType());

            Assert.NotNull(property.TypeUsage);
            Assert.True(property.IsEnumType);
        }
        private EdmProperty MapPrimitiveOrComplexOrEnumProperty(
            PropertyInfo propertyInfo, Func <StructuralTypeConfiguration> structuralTypeConfiguration,
            bool discoverComplexTypes = false)
        {
            DebugCheck.NotNull(propertyInfo);

            var property = propertyInfo.AsEdmPrimitiveProperty();

            if (property == null)
            {
                var propertyType = propertyInfo.PropertyType;
                var complexType  = _typeMapper.MapComplexType(propertyType, discoverComplexTypes);

                if (complexType != null)
                {
                    property = EdmProperty.Complex(propertyInfo.Name, complexType);
                }
                else
                {
                    var isNullable = propertyType.TryUnwrapNullableType(out propertyType);

                    if (propertyType.IsEnum)
                    {
                        var enumType = _typeMapper.MapEnumType(propertyType);

                        if (enumType != null)
                        {
                            property          = EdmProperty.Enum(propertyInfo.Name, enumType);
                            property.Nullable = isNullable;
                        }
                    }
                }
            }

            if (property != null)
            {
                property.SetClrPropertyInfo(propertyInfo);

                new AttributeMapper(_typeMapper.MappingContext.AttributeProvider)
                .Map(propertyInfo, property.Annotations);

                if (!property.IsComplexType)
                {
                    _typeMapper.MappingContext.ConventionsConfiguration.ApplyPropertyConfiguration(
                        propertyInfo,
                        () => structuralTypeConfiguration().Property(new PropertyPath(propertyInfo)),
                        _typeMapper.MappingContext.ModelConfiguration);
                }
            }

            return(property);
        }