Example #1
0
        private ComplexPropertyConfiguration GetComplexPropertyConfiguration(Expression propertyExpression, bool optional = false)
        {
            PropertyInfo propertyInfo             = PropertySelectorVisitor.GetSelectedProperty(propertyExpression);
            ComplexPropertyConfiguration property = _configuration.AddComplexProperty(propertyInfo);

            if (optional)
            {
                property.IsOptional();
            }

            return(property);
        }
Example #2
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;
                    CreatePrimitiveProperty(primitiveProperty, type, config, out edmProperty);
                    break;

                case PropertyKind.Complex:
                    ComplexPropertyConfiguration complexProperty = property as ComplexPropertyConfiguration;
                    IEdmComplexType complexType = _types[complexProperty.RelatedClrType] as IEdmComplexType;

                    edmProperty = 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);
                    }
                    edmProperty = type.AddStructuralProperty(
                        collectionProperty.PropertyInfo.Name,
                        new EdmCollectionTypeReference(
                            new EdmCollectionType(elementTypeReference),
                            collectionProperty.OptionalProperty));
                    break;

                default:
                    break;
                }

                if (edmProperty != null && property.PropertyInfo != null)
                {
                    _properties[property.PropertyInfo] = edmProperty;
                }
            }
        }
Example #3
0
        public virtual ComplexPropertyConfiguration AddComplexProperty(PropertyInfo propertyInfo)
        {
            if (propertyInfo == null)
            {
                throw Error.ArgumentNull("propertyInfo");
            }

            if (!propertyInfo.DeclaringType.IsAssignableFrom(ClrType))
            {
                throw Error.Argument("propertyInfo", SRResources.PropertyDoesNotBelongToType);
            }

            if (propertyInfo.PropertyType == ClrType)
            {
                throw Error.Argument("propertyInfo", SRResources.RecursiveComplexTypesNotAllowed);
            }

            // Remove from the ignored properties
            if (IgnoredProperties.Contains(propertyInfo))
            {
                IgnoredProperties.Remove(propertyInfo);
            }

            ComplexPropertyConfiguration propertyConfiguration = null;

            if (ExplicitProperties.ContainsKey(propertyInfo))
            {
                propertyConfiguration = ExplicitProperties[propertyInfo] as ComplexPropertyConfiguration;
                if (propertyConfiguration == null)
                {
                    throw Error.Argument("propertyInfo", SRResources.MustBeComplexProperty, propertyInfo.Name);
                }
            }
            else
            {
                propertyConfiguration            = new ComplexPropertyConfiguration(propertyInfo);
                ExplicitProperties[propertyInfo] = propertyConfiguration;
                // Make sure the complex type is in the model.

                ModelBuilder.AddComplexType(propertyInfo.PropertyType);
            }

            return(propertyConfiguration);
        }
        public virtual ComplexPropertyConfiguration AddComplexProperty(PropertyInfo propertyInfo)
        {
            if (propertyInfo == null)
            {
                throw Error.ArgumentNull("propertyInfo");
            }

            if (!propertyInfo.DeclaringType.IsAssignableFrom(ClrType))
            {
                throw Error.Argument("propertyInfo", SRResources.PropertyDoesNotBelongToType);
            }

            if (propertyInfo.PropertyType == ClrType)
            {
                throw Error.Argument("propertyInfo", SRResources.RecursiveComplexTypesNotAllowed);
            }

            // Remove from the ignored properties
            if (IgnoredProperties.Contains(propertyInfo))
            {
                IgnoredProperties.Remove(propertyInfo);
            }

            ComplexPropertyConfiguration propertyConfiguration = null;
            if (ExplicitProperties.ContainsKey(propertyInfo))
            {
                propertyConfiguration = ExplicitProperties[propertyInfo] as ComplexPropertyConfiguration;
                if (propertyConfiguration == null)
                {
                    throw Error.Argument("propertyInfo", SRResources.MustBeComplexProperty, propertyInfo.Name);
                }
            }
            else
            {
                propertyConfiguration = new ComplexPropertyConfiguration(propertyInfo);
                ExplicitProperties[propertyInfo] = propertyConfiguration;
                // Make sure the complex type is in the model.

                ModelBuilder.AddComplexType(propertyInfo.PropertyType);
            }

            return propertyConfiguration;
        }
        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;
                }
            }
        }