コード例 #1
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);
        }
コード例 #2
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));
            }
        }