/// <summary>
        /// Gets the entity reference props.
        /// </summary>
        /// <param name="attributeMetadatas">The attribute metadatas.</param>
        /// <param name="oneToManyRelationshipMetadatas">The one to many relationship metadatas.</param>
        /// <returns></returns>
        private PropertyModel[] GetEntityReferenceProps(AttributeMetadata[] attributeMetadatas,
                                                        OneToManyRelationshipMetadata[] oneToManyRelationshipMetadatas)
        {
            var propertyModels = new List <PropertyModel>();

            foreach (var attributeMetadata in attributeMetadatas)
            {
                if (FieldsFactory.IsLookup(attributeMetadata))
                {
                    var schemaName          = attributeMetadata.SchemaName;
                    var propertyLogicalName = attributeMetadata.LogicalName;
                    var lookupTargetEntity  = ((LookupAttributeMetadata)attributeMetadata).Targets.FirstOrDefault();
                    var description         = Helpers.GetDescription(attributeMetadata.Description);
                    var valueField          = $"_{propertyLogicalName}_value";

                    if (lookupTargetEntity != null)
                    {
                        var entityLogicalName = lookupTargetEntity;
                        var entityMetadata    = _metadataRepository.GetEntityMetadata(entityLogicalName);
                        var entitySetName     = entityMetadata.EntitySetName;
                        var type          = Helpers.EntityReference;
                        var attributeName = GetAttributeName(oneToManyRelationshipMetadatas, lookupTargetEntity, schemaName);

                        var entityReferenceAttributeModel = new EntityReferenceAttributeModel()
                        {
                            ValueField    = valueField,
                            EntitySetName = entitySetName
                        };

                        propertyModels.Add(new PropertyModel()
                        {
                            AttributeName = attributeName,
                            Description   = description,
                            PropertyName  = schemaName,
                            Type          = type,
                            Attributes    =
                            {
                                entityReferenceAttributeModel
                            }
                        });

                        AddEntityPropertyIfContains(entityLogicalName, propertyModels, schemaName, description, entityMetadata);
                    }
                }
            }

            return(propertyModels.ToArray());
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the props.
        /// </summary>
        /// <param name="attributeMetadatas">The attribute metadatas.</param>
        /// <returns></returns>
        private PropertyModel[] GetProps(IEnumerable <AttributeMetadata> attributeMetadatas)
        {
            var propertyModels = new List <PropertyModel>();

            foreach (var attributeMetadata in attributeMetadatas)
            {
                if (attributeMetadata.AttributeType != AttributeTypeCode.Lookup &&
                    attributeMetadata.AttributeType.HasValue)
                {
                    var attributeType = attributeMetadata.AttributeType.Value;

                    if (FieldsFactory.IsSupportedType(attributeMetadata) &&
                        !FieldsFactory.IsLookup(attributeMetadata))
                    {
                        var type          = Helpers.Types[attributeType];
                        var propertyName  = attributeMetadata.SchemaName;
                        var attributeName = attributeMetadata.SchemaName;
                        var description   = Helpers.GetDescription(attributeMetadata.Description);

                        var propertyModel = new PropertyModel()
                        {
                            Description   = description,
                            AttributeName = attributeName,
                            PropertyName  = propertyName,
                            Type          = type
                        };

                        if (attributeType == AttributeTypeCode.DateTime &&
                            attributeMetadata is DateTimeAttributeMetadata dateTimeAttributeMetadata)
                        {
                            if (dateTimeAttributeMetadata.Format == DateTimeFormat.DateOnly)
                            {
                                propertyModel.Attributes.Add(new DateOnlyAttributeModel());
                            }
                        }

                        propertyModels.Add(propertyModel);
                    }
                }
            }

            return(propertyModels.ToArray());
        }