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;
                }
            }
        }
Пример #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));
            }
        }