public void Enum_should_create_property_type() { var property = EdmProperty.CreateEnum("P", new EnumType()); Assert.NotNull(property.TypeUsage); Assert.True(property.IsEnumType); }
private static EdmType CreateResultType(DbModel model, ResultDescriptor result) { EdmType edmType = GetSimpleEdmType(model, result.Type); if (edmType == null) { edmType = GetStructuralEdmType(model, result.Type); } if (edmType == null) { throw new InvalidOperationException(string.Format("Edm type is not found for result type {0}.", result.Type.FullName)); } switch (edmType.BuiltInTypeKind) { case BuiltInTypeKind.EntityType: var propertyMappings = ((EntityType)edmType).Properties.Join( model.ConceptualToStoreMapping.EntitySetMappings .SelectMany(t => t.EntityTypeMappings) .Where(t => edmType.Yield(e => e.BaseType, (e, b) => b, e => e != null).Contains(t.EntityType)) .SelectMany(tm => tm.Fragments.SelectMany(t => t.PropertyMappings)) .OfType <ScalarPropertyMapping>(), p => p, pm => pm.Property, (p, pm) => new { Property = p, TypeUsage = TypeUsage.Create(pm.Column.TypeUsage.EdmType, pm.Column.TypeUsage.Facets.Where(f => !new[] { "StoreGeneratedPattern", "ConcurrencyMode" }.Contains(f.Name))) }); return(RowType.Create(propertyMappings.Select(pm => EdmProperty.Create(pm.Property.Name, pm.TypeUsage)), null)); case BuiltInTypeKind.ComplexType: return(RowType.Create(((StructuralType)edmType).Members.Select(m => { string columnName = null; MetadataProperty metadata; //if (!m.MetadataProperties.TryGetValue("Configuration", true, out metadata) || !metadata.Value.TryGetProperty("ColumnName", out columnName)) if (m.MetadataProperties.TryGetValue("ClrAttributes", true, out metadata)) { var columnAttr = ((IEnumerable)m.MetadataProperties["ClrAttributes"].Value).OfType <ColumnAttribute>().SingleOrDefault(); if (columnAttr != null && !string.IsNullOrEmpty(columnAttr.Name)) { columnName = columnAttr.Name; } } return EdmProperty.Create(columnName ?? m.Name, model.ProviderManifest.GetStoreType(m.TypeUsage)); }), null)); case BuiltInTypeKind.EnumType: return(RowType.Create(new[] { EdmProperty.CreateEnum(result.ColumnName, (EnumType)edmType) }, null)); case BuiltInTypeKind.PrimitiveType: return(RowType.Create(new[] { EdmProperty.CreatePrimitive(result.ColumnName, (PrimitiveType)edmType) }, null)); default: throw new NotSupportedException(); } }
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.CreateComplex(propertyInfo.Name, complexType); } else { var isNullable = propertyType.TryUnwrapNullableType(out propertyType); if (propertyType.IsEnum()) { var enumType = _typeMapper.MapEnumType(propertyType); if (enumType != null) { property = EdmProperty.CreateEnum(propertyInfo.Name, enumType); property.Nullable = isNullable; } } } } if (property != null) { property.SetClrPropertyInfo(propertyInfo); new AttributeMapper(_typeMapper.MappingContext.AttributeProvider) .Map(propertyInfo, property.GetMetadataProperties()); if (!property.IsComplexType) { _typeMapper.MappingContext.ConventionsConfiguration.ApplyPropertyConfiguration( propertyInfo, () => structuralTypeConfiguration().Property(new PropertyPath(propertyInfo)), _typeMapper.MappingContext.ModelConfiguration); } } return(property); }
private EdmProperty MapPrimitiveOrComplexOrEnumProperty( PropertyInfo propertyInfo, Func <StructuralTypeConfiguration> structuralTypeConfiguration, bool discoverComplexTypes = false) { EdmProperty property = propertyInfo.AsEdmPrimitiveProperty(); if (property == null) { Type underlyingType = propertyInfo.PropertyType; ComplexType complexType = this._typeMapper.MapComplexType(underlyingType, discoverComplexTypes); if (complexType != null) { property = EdmProperty.CreateComplex(propertyInfo.Name, complexType); } else { bool flag = underlyingType.TryUnwrapNullableType(out underlyingType); if (underlyingType.IsEnum()) { EnumType enumType = this._typeMapper.MapEnumType(underlyingType); if (enumType != null) { property = EdmProperty.CreateEnum(propertyInfo.Name, enumType); property.Nullable = flag; } } } } if (property != null) { property.SetClrPropertyInfo(propertyInfo); new AttributeMapper(this._typeMapper.MappingContext.AttributeProvider).Map(propertyInfo, (ICollection <MetadataProperty>)property.GetMetadataProperties()); if (!property.IsComplexType) { this._typeMapper.MappingContext.ConventionsConfiguration.ApplyPropertyConfiguration(propertyInfo, (Func <PropertyConfiguration>)(() => (PropertyConfiguration)structuralTypeConfiguration().Property(new PropertyPath(propertyInfo), new OverridableConfigurationParts?())), this._typeMapper.MappingContext.ModelConfiguration); } } return(property); }