protected override void GenerateProperties(IEntityType entityType)
        {
            var properties = new List <Dictionary <string, object> >();

#pragma warning disable EF1001 // Internal EF Core API usage.
            foreach (var property in entityType.GetProperties().OrderBy(p => p.GetColumnOrdinal()))
#pragma warning restore EF1001 // Internal EF Core API usage.
            {
                PropertyAnnotationsData = new List <Dictionary <string, object> >();

                if (UseDataAnnotations)
                {
                    GeneratePropertyDataAnnotations(property);
                }

                var propertyType = CSharpHelper.Reference(property.ClrType);
                if (_options?.Value?.EnableNullableReferenceTypes == true &&
                    property.IsNullable &&
                    !propertyType.EndsWith("?"))
                {
                    propertyType += "?";
                }
                properties.Add(new Dictionary <string, object>
                {
                    { "property-type", propertyType },
                    { "property-name", property.Name },
                    { "property-annotations", PropertyAnnotationsData },
                    { "property-comment", property.GetComment() },
                    { "property-isnullable", property.IsNullable },
                    { "nullable-reference-types", _options?.Value?.EnableNullableReferenceTypes == true },

                    // Add new item to template data
                    { "property-isprimarykey", property.IsPrimaryKey() }
                });
            }

            var transformedProperties = EntityTypeTransformationService.TransformProperties(properties);

            // Add to transformed properties
            for (int i = 0; i < transformedProperties.Count; i++)
            {
                transformedProperties[i].Add("property-isprimarykey", properties[i]["property-isprimarykey"]);
            }

            TemplateData.Add("properties", transformedProperties);
        }
示例#2
0
        /// <summary>
        /// Generate entity type properties.
        /// </summary>
        /// <param name="entityType">Represents an entity type in an <see cref="T:Microsoft.EntityFrameworkCore.Metadata.IModel" />.</param>
        protected override void GenerateProperties(IEntityType entityType)
        {
            Check.NotNull(entityType, nameof(entityType));

            var properties = new List <Dictionary <string, object> >();

            foreach (var property in entityType.GetProperties().OrderBy(p => p.GetColumnOrdinal()))
            {
                properties.Add(new Dictionary <string, object>
                {
                    { "property-type", TypeScriptHelper.TypeName(property.ClrType) },
                    { "property-name", TypeScriptHelper.ToCamelCase(property.Name) },
                    { "property-annotations", new List <Dictionary <string, object> >() },
                    { "property-comment", property.GetComment() },
                    { "property-isnullable", property.IsNullable },
                    { "nullable-reference-types", _options?.Value?.EnableNullableReferenceTypes == true }
                });
            }

            var transformedProperties = EntityTypeTransformationService.TransformProperties(entityType.Name, properties);

            TemplateData.Add("properties", transformedProperties);
        }
        /// <summary>
        /// Generate entity type properties.
        /// </summary>
        /// <param name="entityType">Represents an entity type in an <see cref="T:Microsoft.EntityFrameworkCore.Metadata.IModel" />.</param>
        protected override void GenerateProperties(IEntityType entityType)
        {
            Check.NotNull(entityType, nameof(entityType));

            var properties = new List <Dictionary <string, object> >();

            foreach (var property in entityType.GetProperties().OrderBy(p => p.GetColumnOrdinal()))
            {
                PropertyAnnotationsData = new List <Dictionary <string, object> >();

                if (UseDataAnnotations)
                {
                    GeneratePropertyDataAnnotations(property);
                }

                var propertyType = CSharpHelper.Reference(property.ClrType);
                if (_options?.Value?.EnableNullableReferenceTypes == true &&
                    property.IsNullable &&
                    !propertyType.EndsWith("?"))
                {
                    propertyType += "?";
                }
                properties.Add(new Dictionary <string, object>
                {
                    { "property-type", propertyType },
                    { "property-name", property.Name },
                    { "property-annotations", PropertyAnnotationsData },
                    { "property-comment", _options?.Value?.GenerateComments == true ? GenerateComment(property.GetComment(), 2) : null },
                    { "property-isnullable", property.IsNullable },
                    { "nullable-reference-types", _options?.Value?.EnableNullableReferenceTypes == true }
                });
            }

            var transformedProperties = EntityTypeTransformationService.TransformProperties(entityType.Name, properties);

            TemplateData.Add("properties", transformedProperties);
        }