コード例 #1
0
        internal void MapProperties(Type instanceType, StructuralTypeConfiguration configuration)
        {
            var metaDatas = query.GetMetadataFor(instanceType).Properties;

            foreach (var data in metaDatas)
            {
                if (data.ModelName == null)
                {
                    continue;
                }
                if (!data.StringLength.HasValue && !data.Required.HasValue)
                {
                    continue;
                }
                var methodInfo = methodMapping.GetPropertyMappingMethod(configuration.GetType(), instanceType,
                                                                        data.ModelType);
                if (methodInfo == null)
                {
                    continue;
                }

                var lambda = generator.CreateExpressionForProperty(instanceType, data.ModelName);
                if (lambda != null)
                {
                    var propertyConfiguration = (PropertyConfiguration) methodInfo.Invoke(configuration, new[] {lambda});

                    factory.Create(propertyConfiguration).Convert(data, propertyConfiguration);
                }
            }
        }
コード例 #2
0
 public override void Apply(TPropertyConfiguration edmProperty,
                            StructuralTypeConfiguration structuralTypeConfiguration, Attribute attribute)
 {
     Called = true;
 }
コード例 #3
0
 /// <summary>
 /// Applies the convention.
 /// </summary>
 /// <param name="edmProperty">The property being configured.</param>
 /// <param name="structuralTypeConfiguration">The type being configured.</param>
 /// <param name="attribute">The attribute to be used during configuration.</param>
 public abstract void Apply(TPropertyConfiguration edmProperty, StructuralTypeConfiguration structuralTypeConfiguration, Attribute attribute);
コード例 #4
0
 /// <summary>
 /// Applies the convention.
 /// </summary>
 /// <param name="edmProperty">The property being configured.</param>
 /// <param name="structuralTypeConfiguration">The type being configured.</param>
 /// <param name="attribute">The attribute to be used during configuration.</param>
 /// <param name="model">The ODataConventionModelBuilder used to build the model.</param>
 public abstract void Apply(TPropertyConfiguration edmProperty,
                            StructuralTypeConfiguration structuralTypeConfiguration,
                            Attribute attribute,
                            ODataConventionModelBuilder model);
 internal static IEdmTypeConfiguration ToEdmTypeConfiguration <T>(this StructuralTypeConfiguration <T> configuration) where T : class
 {
     Contract.Requires(configuration != null);
     Contract.Ensures(Contract.Result <IEdmTypeConfiguration>() != null);
     return(new EdmTypeConfigurationAdapter <T>(configuration));
 }
 internal EdmTypeConfigurationAdapter(StructuralTypeConfiguration <T> configuration)
 {
     Contract.Requires(configuration != null);
     this.configuration = configuration;
     innerConfiguration = new Lazy <StructuralTypeConfiguration>(configuration.GetInnerConfiguration);
 }
コード例 #7
0
 /// <summary>
 /// Instantiates a new instance of the <see cref="InstanceAnnotationConfiguration{TStructuralType}"/> class.
 /// </summary>
 /// <param name="configuration">The associated <see cref="StructuralTypeConfiguration{TStructuralType}">configuration</see>.</param>
 /// <param name="name">The name of the annotation.</param>
 /// <param name="annotation">The <see cref="InstanceAnnotation">annotation</see> to configure.</param>
 public InstanceAnnotationConfiguration(StructuralTypeConfiguration <TStructuralType> configuration, string name, InstanceAnnotation annotation)
     : base(configuration?.ToEdmTypeConfiguration(), name, annotation)
 {
     Arg.NotNull(configuration, nameof(configuration));
     this.configuration = configuration;
 }
コード例 #8
0
ファイル: EdmTypeBuilder.cs プロジェクト: g2mula/ModelBuilder
        private void CreateEdmTypeHeader(IEdmTypeConfiguration config)
        {
            IEdmType edmType = GetEdmType(config.ClrType);

            if (edmType == null)
            {
                if (config.Kind == EdmTypeKind.Complex)
                {
                    ComplexTypeConfiguration complex  = (ComplexTypeConfiguration)config;
                    IEdmComplexType          baseType = null;
                    if (complex.BaseType != null)
                    {
                        CreateEdmTypeHeader(complex.BaseType);
                        baseType = GetEdmType(complex.BaseType.ClrType) as IEdmComplexType;

                        Contract.Assert(baseType != null);
                    }

                    EdmComplexType complexType = new EdmComplexType(config.Namespace, config.Name,
                                                                    baseType, complex.IsAbstract ?? false, complex.IsOpen);

                    _types.Add(config.ClrType, complexType);

                    if (complex.IsOpen)
                    {
                        // add a mapping between the open complex type and its dynamic property dictionary.
                        _openTypes.Add(complexType, complex.DynamicPropertyDictionary);
                    }
                    edmType = complexType;
                }
                else if (config.Kind == EdmTypeKind.Entity)
                {
                    EntityTypeConfiguration entity = config as EntityTypeConfiguration;
                    Contract.Assert(entity != null);

                    IEdmEntityType baseType = null;
                    if (entity.BaseType != null)
                    {
                        CreateEdmTypeHeader(entity.BaseType);
                        baseType = GetEdmType(entity.BaseType.ClrType) as IEdmEntityType;

                        Contract.Assert(baseType != null);
                    }

                    EdmEntityType entityType = new EdmEntityType(config.Namespace, config.Name, baseType,
                                                                 entity.IsAbstract ?? false, entity.IsOpen, entity.HasStream);
                    _types.Add(config.ClrType, entityType);

                    if (entity.IsOpen)
                    {
                        // add a mapping between the open entity type and its dynamic property dictionary.
                        _openTypes.Add(entityType, entity.DynamicPropertyDictionary);
                    }
                    edmType = entityType;
                }
                else
                {
                    EnumTypeConfiguration enumTypeConfiguration = config as EnumTypeConfiguration;

                    // The config has to be enum.
                    Contract.Assert(enumTypeConfiguration != null);

                    _types.Add(enumTypeConfiguration.ClrType,
                               new EdmEnumType(enumTypeConfiguration.Namespace, enumTypeConfiguration.Name,
                                               GetTypeKind(enumTypeConfiguration.UnderlyingType), enumTypeConfiguration.IsFlags));
                }
            }

            IEdmStructuredType          structuredType = edmType as IEdmStructuredType;
            StructuralTypeConfiguration structuralTypeConfiguration = config as StructuralTypeConfiguration;

            if (structuredType != null && structuralTypeConfiguration != null &&
                !_structuredTypeQuerySettings.ContainsKey(structuredType))
            {
                //ModelBoundQuerySettings querySettings =
                //    structuralTypeConfiguration.QueryConfiguration.ModelBoundQuerySettings;
                //if (querySettings != null)
                //{
                //    _structuredTypeQuerySettings.Add(structuredType,
                //        structuralTypeConfiguration.QueryConfiguration.ModelBoundQuerySettings);
                //}
            }
        }
コード例 #9
0
ファイル: EdmTypeBuilder.cs プロジェクト: g2mula/ModelBuilder
        private void CreateStructuralTypeBody(EdmStructuredType type, StructuralTypeConfiguration config)
        {
            foreach (PropertyConfiguration property in config.Properties)
            {
                IEdmProperty edmProperty = null;

                switch (property.Kind)
                {
                case PropertyKind.Primitive:
                    PrimitivePropertyConfiguration primitiveProperty = (PrimitivePropertyConfiguration)property;
                    EdmPrimitiveTypeKind           typeKind          = primitiveProperty.TargetEdmTypeKind ??
                                                                       GetTypeKind(primitiveProperty.PropertyInfo.PropertyType);
                    IEdmTypeReference primitiveTypeReference = EdmCoreModel.Instance.GetPrimitive(
                        typeKind,
                        primitiveProperty.NullableProperty);

                    if (typeKind == EdmPrimitiveTypeKind.Decimal)
                    {
                        DecimalPropertyConfiguration decimalProperty =
                            primitiveProperty as DecimalPropertyConfiguration;
                        if (decimalProperty.Precision.HasValue || decimalProperty.Scale.HasValue)
                        {
                            primitiveTypeReference = new EdmDecimalTypeReference(
                                (IEdmPrimitiveType)primitiveTypeReference.Definition,
                                primitiveTypeReference.IsNullable,
                                decimalProperty.Precision,
                                decimalProperty.Scale.HasValue ? decimalProperty.Scale : 0);
                        }
                    }
                    else if (EdmLibHelpers.HasPrecision(typeKind))
                    {
                        PrecisionPropertyConfiguration precisionProperty =
                            primitiveProperty as PrecisionPropertyConfiguration;
                        primitiveTypeReference = AddPrecisionConfigInPrimitiveTypeReference(
                            precisionProperty,
                            primitiveTypeReference);
                    }
                    else if (EdmLibHelpers.HasLength(typeKind))
                    {
                        LengthPropertyConfiguration lengthProperty =
                            primitiveProperty as LengthPropertyConfiguration;
                        primitiveTypeReference = AddLengthConfigInPrimitiveTypeReference(
                            lengthProperty,
                            primitiveTypeReference);
                    }
                    edmProperty = type.AddStructuralProperty(
                        primitiveProperty.Name,
                        primitiveTypeReference,
                        defaultValue: primitiveProperty.DefaultValueString);
                    break;

                case PropertyKind.Complex:
                    ComplexPropertyConfiguration complexProperty = property as ComplexPropertyConfiguration;
                    IEdmComplexType complexType = GetEdmType(complexProperty.RelatedClrType) as IEdmComplexType;

                    edmProperty = type.AddStructuralProperty(
                        complexProperty.Name,
                        new EdmComplexTypeReference(complexType, complexProperty.NullableProperty));
                    break;

                case PropertyKind.Collection:
                    edmProperty = CreateStructuralTypeCollectionPropertyBody(type, (CollectionPropertyConfiguration)property);
                    break;

                case PropertyKind.Enum:
                    edmProperty = CreateStructuralTypeEnumPropertyBody(type, (EnumPropertyConfiguration)property);
                    break;

                default:
                    break;
                }

                if (edmProperty != null)
                {
                    if (property.PropertyInfo != null)
                    {
                        _properties[property.PropertyInfo] = edmProperty;
                    }

                    if (property.IsRestricted)
                    {
                        _propertiesRestrictions[edmProperty] = new QueryableRestrictions(property);
                    }

                    //if (property.QueryConfiguration.ModelBoundQuerySettings != null)
                    //{
                    //    _propertiesQuerySettings.Add(edmProperty, property.QueryConfiguration.ModelBoundQuerySettings);
                    //}
                }
            }
        }
コード例 #10
0
ファイル: EdmTypeBuilder.cs プロジェクト: g2mula/ModelBuilder
        private void CreateNavigationProperty(StructuralTypeConfiguration config)
        {
            Contract.Assert(config != null);

            EdmStructuredType type = (EdmStructuredType)(GetEdmType(config.ClrType));

            foreach (NavigationPropertyConfiguration navProp in config.NavigationProperties)
            {
                Func <NavigationPropertyConfiguration, EdmNavigationPropertyInfo> getInfo = nav =>
                {
                    EdmNavigationPropertyInfo info = new EdmNavigationPropertyInfo
                    {
                        Name = nav.Name,
                        TargetMultiplicity = nav.Multiplicity,
                        Target             = GetEdmType(nav.RelatedClrType) as IEdmEntityType,
                        ContainsTarget     = nav.ContainsTarget,
                        OnDelete           = nav.OnDeleteAction
                    };

                    // Principal properties
                    if (nav.PrincipalProperties.Any())
                    {
                        info.PrincipalProperties = GetDeclaringPropertyInfo(nav.PrincipalProperties);
                    }

                    // Dependent properties
                    if (nav.DependentProperties.Any())
                    {
                        info.DependentProperties = GetDeclaringPropertyInfo(nav.DependentProperties);
                    }

                    return(info);
                };

                var           navInfo    = getInfo(navProp);
                var           props      = new Dictionary <IEdmProperty, NavigationPropertyConfiguration>();
                EdmEntityType entityType = type as EdmEntityType;
                if (entityType != null && navProp.Partner != null)
                {
                    var edmProperty        = entityType.AddBidirectionalNavigation(navInfo, getInfo(navProp.Partner));
                    var partnerEdmProperty = (navInfo.Target as EdmEntityType).Properties().Single(p => p.Name == navProp.Partner.Name);
                    props.Add(edmProperty, navProp);
                    props.Add(partnerEdmProperty, navProp.Partner);
                }
                else
                {
                    // Do not add this if we have have a partner relationship configured, as this
                    // property will be added automatically through the AddBidirectionalNavigation
                    var targetConfig = config.ModelBuilder.GetTypeConfigurationOrNull(navProp.RelatedClrType) as StructuralTypeConfiguration;
                    if (!targetConfig.NavigationProperties.Any(p => p.Partner != null && p.Partner.Name == navInfo.Name))
                    {
                        var edmProperty = type.AddUnidirectionalNavigation(navInfo);
                        props.Add(edmProperty, navProp);
                    }
                }

                foreach (var item in props)
                {
                    var edmProperty = item.Key;
                    var prop        = item.Value;
                    if (prop.PropertyInfo != null)
                    {
                        _properties[prop.PropertyInfo] = edmProperty;
                    }


                    if (prop.IsRestricted)
                    {
                        _propertiesRestrictions[edmProperty] = new QueryableRestrictions(prop);
                    }

                    /*
                     *                 if (prop.QueryConfiguration.ModelBoundQuerySettings != null)
                     *                 {
                     *                     _propertiesQuerySettings.Add(edmProperty, prop.QueryConfiguration.ModelBoundQuerySettings);
                     *                 }*/
                }
            }
        }