private void GenerateColumnAttribute(IProperty property)
        {
            var columnName = property.GetColumnName();
            var columnType = property.GetConfiguredColumnType();

            var delimitedColumnName = columnName != null && columnName != property.Name ? CSharpHelper.Literal(columnName) : null;
            var delimitedColumnType = columnType != null?CSharpHelper.Literal(columnType) : null;

            if ((delimitedColumnName ?? delimitedColumnType) != null)
            {
                var columnAttribute = new AttributeWriter(nameof(ColumnAttribute));

                if (delimitedColumnName != null)
                {
                    columnAttribute.AddParameter(delimitedColumnName);
                }

                if (delimitedColumnType != null)
                {
                    columnAttribute.AddParameter($"{nameof(ColumnAttribute.TypeName)} = {delimitedColumnType}");
                }

                PropertyAnnotationsData.Add(new Dictionary <string, object>
                {
                    { "property-annotation", columnAttribute },
                });
            }
        }
 private void GenerateRequiredAttribute(IProperty property)
 {
     if (!property.IsNullable &&
         property.ClrType.IsNullableType() &&
         !property.IsPrimaryKey())
     {
         PropertyAnnotationsData.Add(new Dictionary <string, object>
         {
             { "property-annotation", new AttributeWriter(nameof(RequiredAttribute)).ToString() },
         });
     }
 }
        private void GenerateKeyAttribute(IProperty property)
        {
            var key = property.FindContainingPrimaryKey();

            if (key != null)
            {
                PropertyAnnotationsData.Add(new Dictionary <string, object>
                {
                    { "property-annotation", new AttributeWriter(nameof(KeyAttribute)) },
                });
            }
        }
        private void GenerateMaxLengthAttribute(IProperty property)
        {
            var maxLength = property.GetMaxLength();

            if (maxLength.HasValue)
            {
                var lengthAttribute = new AttributeWriter(
                    property.ClrType == typeof(string)
                        ? nameof(StringLengthAttribute)
                        : nameof(MaxLengthAttribute));

                lengthAttribute.AddParameter(CSharpHelper.Literal(maxLength.Value));

                PropertyAnnotationsData.Add(new Dictionary <string, object>
                {
                    { "property-annotation", lengthAttribute.ToString() },
                });
            }
        }
        private void GenerateKeyAttribute(IProperty property)
        {
            var key = property.AsProperty().PrimaryKey;

            if (key?.Properties.Count == 1)
            {
                if (key is Key concreteKey &&
                    key.Properties.SequenceEqual(new KeyDiscoveryConvention(null).DiscoverKeyProperties(concreteKey.DeclaringEntityType, concreteKey.DeclaringEntityType.GetProperties().ToList())))
                {
                    return;
                }

                if (key.Relational().Name != ConstraintNamer.GetDefaultName(key))
                {
                    return;
                }

                PropertyAnnotationsData.Add(new Dictionary <string, object>
                {
                    { "property-annotation", new AttributeWriter(nameof(KeyAttribute)) },
                });
            }
        }