private IEdmTypeReference GetEdmTypeReference(Type clrType, Dictionary <Type, EntityTypeInfo> entityTypeInfos)
        {
            bool nullable = PrimitiveTypeHelper.IsNullable(clrType);

            if (nullable)
            {
                Type underlyingType = Nullable.GetUnderlyingType(clrType);
                if (underlyingType != null)
                {
                    clrType = underlyingType;
                }
            }

            if (entityTypeInfos.TryGetValue(clrType, out EntityTypeInfo entityTypeInfo))
            {
                return(new EdmEntityTypeReference(entityTypeInfo.EdmType, nullable));
            }

            if (_enumTypes.TryGetValue(clrType, out EdmEnumType edmEnumType))
            {
                return(new EdmEnumTypeReference(edmEnumType, nullable));
            }

            if (_complexTypes.TryGetValue(clrType, out EdmComplexType edmComplexType))
            {
                return(new EdmComplexTypeReference(edmComplexType, nullable));
            }

            return(PrimitiveTypeHelper.GetPrimitiveTypeRef(clrType, nullable));
        }
Exemplo n.º 2
0
        private EdmStructuralProperty?BuildStructuralProperty(Dictionary <Type, EntityTypeInfo> entityTypes,
                                                              Dictionary <Type, EdmEnumType> enumTypes, Dictionary <Type, EdmComplexType> complexTypes, PropertyInfo clrProperty)
        {
            bool isNullable           = !_metadataProvider.IsRequired(clrProperty);
            IEdmTypeReference?typeRef = PrimitiveTypeHelper.GetPrimitiveTypeRef(clrProperty, isNullable);

            if (typeRef == null)
            {
                Type?underlyingType = null;
                if (clrProperty.PropertyType.IsEnum ||
                    (underlyingType = Nullable.GetUnderlyingType(clrProperty.PropertyType)) != null && underlyingType.IsEnum)
                {
                    Type clrPropertyType = underlyingType ?? clrProperty.PropertyType;
                    if (!enumTypes.TryGetValue(clrPropertyType, out EdmEnumType? edmEnumType))
                    {
                        edmEnumType = OeEdmModelBuilder.CreateEdmEnumType(clrPropertyType);
                        enumTypes.Add(clrPropertyType, edmEnumType);
                    }
                    typeRef = new EdmEnumTypeReference(edmEnumType, underlyingType != null);
                }
                else
                {
                    if (complexTypes.TryGetValue(clrProperty.PropertyType, out EdmComplexType? edmComplexType))
                    {
                        typeRef = new EdmComplexTypeReference(edmComplexType, clrProperty.PropertyType.IsClass);
                    }
                    else
                    {
                        FKeyInfo?fkeyInfo = FKeyInfo.Create(_metadataProvider, entityTypes, this, clrProperty);
                        if (fkeyInfo != null)
                        {
                            _navigationClrProperties.Add(fkeyInfo);
                        }
                        return(null);
                    }
                }
            }
            else
            {
                if (clrProperty.PropertyType == typeof(DateTime?) && enumTypes.ContainsKey(typeof(DateTime?)))
                {
                    var edmType = enumTypes[typeof(DateTime?)];
                    typeRef = new EdmEnumTypeReference(edmType, true);
                }
            }

            EdmStructuralProperty edmProperty = clrProperty is Infrastructure.OeShadowPropertyInfo ?
                                                new OeEdmStructuralShadowProperty(EdmType, clrProperty.Name, typeRef, clrProperty) :
                                                new EdmStructuralProperty(EdmType, clrProperty.Name, typeRef);

            EdmType.AddProperty(edmProperty);
            if (_metadataProvider.IsKey(clrProperty))
            {
                _keyProperties.Add(new KeyValuePair <PropertyInfo, EdmStructuralProperty>(clrProperty, edmProperty));
            }

            return(edmProperty);
        }
Exemplo n.º 3
0
        private void BuildProperty(Dictionary <Type, EntityTypeInfo> entityTypes,
                                   Dictionary <Type, EdmEnumType> enumTypes, Dictionary <Type, EdmComplexType> complexTypes, PropertyDescriptor clrProperty)
        {
            IEdmTypeReference typeRef = PrimitiveTypeHelper.GetPrimitiveTypeRef(clrProperty);

            if (typeRef == null)
            {
                EdmEnumType edmEnumType;
                Type        underlyingType = null;
                if (clrProperty.PropertyType.GetTypeInfo().IsEnum ||
                    (underlyingType = Nullable.GetUnderlyingType(clrProperty.PropertyType)) != null && underlyingType.GetTypeInfo().IsEnum)
                {
                    Type clrPropertyType = underlyingType ?? clrProperty.PropertyType;
                    if (!enumTypes.TryGetValue(clrPropertyType, out edmEnumType))
                    {
                        edmEnumType = CreateEdmEnumType(clrPropertyType);
                        enumTypes.Add(clrPropertyType, edmEnumType);
                    }
                    typeRef = new EdmEnumTypeReference(edmEnumType, underlyingType != null);
                }
                else
                {
                    EdmComplexType edmComplexType;
                    if (complexTypes.TryGetValue(clrProperty.PropertyType, out edmComplexType))
                    {
                        typeRef = new EdmComplexTypeReference(edmComplexType, clrProperty.PropertyType.GetTypeInfo().IsClass);
                    }
                    else
                    {
                        FKeyInfo fkeyInfo = FKeyInfo.Create(_metadataProvider, entityTypes, this, clrProperty);
                        if (fkeyInfo != null)
                        {
                            _navigationClrProperties.Add(fkeyInfo);
                        }
                        return;
                    }
                }
            }
            else
            {
                if (clrProperty.PropertyType == typeof(DateTime?) && enumTypes.ContainsKey(typeof(DateTime?))) //zzz
                {
                    var edmType = enumTypes[typeof(DateTime?)];
                    typeRef = new EdmEnumTypeReference(edmType, true);
                }
            }

            var edmProperty = new EdmStructuralProperty(_edmType, clrProperty.Name, typeRef);

            _edmType.AddProperty(edmProperty);
            if (_metadataProvider.IsKey(clrProperty))
            {
                _keyProperties.Add(new KeyValuePair <PropertyDescriptor, EdmStructuralProperty>(clrProperty, edmProperty));
            }
        }
Exemplo n.º 4
0
        private IEdmTypeReference GetEdmTypeReference(Type clrType, Dictionary <Type, EntityTypeInfo> entityTypeInfos)
        {
            bool nullable = PrimitiveTypeHelper.IsNullable(clrType);

            if (nullable)
            {
                Type underlyingType = Nullable.GetUnderlyingType(clrType);
                if (underlyingType != null)
                {
                    clrType = underlyingType;
                }
            }

            if (entityTypeInfos.TryGetValue(clrType, out EntityTypeInfo entityTypeInfo))
            {
                return(new EdmEntityTypeReference(entityTypeInfo.EdmType, nullable));
            }

            if (_enumTypes.TryGetValue(clrType, out EdmEnumType edmEnumType))
            {
                return(new EdmEnumTypeReference(edmEnumType, nullable));
            }

            if (_complexTypes.TryGetValue(clrType, out EdmComplexType edmComplexType))
            {
                return(new EdmComplexTypeReference(edmComplexType, nullable));
            }

            IEdmTypeReference typeRef = PrimitiveTypeHelper.GetPrimitiveTypeRef(clrType, nullable);

            if (typeRef != null)
            {
                return(typeRef);
            }

            Type itemType = Parsers.OeExpressionHelper.GetCollectionItemType(clrType);

            if (itemType != null)
            {
                typeRef = GetEdmTypeReference(itemType, entityTypeInfos);
                return(new EdmCollectionTypeReference(new EdmCollectionType(typeRef)));
            }

            throw new InvalidOperationException("Not suppoertyed parameter type " + clrType.FullName);
        }