private string GetAttributeMapping(AttributeModel attribute) { var statements = new List<string>(); statements.Add($"builder.Property(x => x.{ attribute.Name.ToPascalCase() })"); if (!attribute.Type.IsNullable) { statements.Add(".IsRequired()"); } if (attribute.GetPrimaryKey()?.Identity() == true) { statements.Add(".UseSqlServerIdentityColumn()"); } if (attribute.GetDefaultConstraint()?.Value() != null) { var defaultValue = attribute.GetDefaultConstraint().Value(); statements.Add($".HasDefaultValueSql({(attribute.Type.Element.Name == "string" ? $"\"{ defaultValue }\"" : defaultValue)})"); } var maxLength = attribute.GetTextConstraints()?.MaxLength(); if (maxLength.HasValue && attribute.Type.Element.Name == "string") { statements.Add($".HasMaxLength({maxLength.Value})"); } var decimalPrecision = attribute.GetDecimalConstraints()?.Precision(); var decimalScale = attribute.GetDecimalConstraints()?.Scale(); var columnType = attribute.GetColumn()?.Type(); if (decimalPrecision.HasValue && decimalScale.HasValue) { statements.Add($".HasColumnType(\"decimal({ decimalPrecision }, { decimalScale })\")"); } else if (!string.IsNullOrWhiteSpace(columnType)) { statements.Add($".HasColumnType(\"{columnType}\")"); } var columnName = attribute.GetColumn()?.Name(); if (!string.IsNullOrWhiteSpace(columnName)) { statements.Add($".HasColumnName(\"{columnName}\")"); } var computedValueSql = attribute.GetComputedValue()?.SQL(); if (!string.IsNullOrWhiteSpace(computedValueSql)) { statements.Add($".HasComputedColumnSql(\"{computedValueSql}\"{(attribute.GetComputedValue().Stored() ? ", stored: true" : string.Empty)})"); } return $@" {string.Join(@" ", statements)};"; }