Ejemplo n.º 1
0
        private string GenEntityClass(TableModel table)
        {
            var columns = table.Columns.Select(x => new
            {
                x.TableName,
                x.ColumnName,
                x.DataType,
                x.IsNullable,
                x.Description,
                x.CharacterMaximumLength,
                x.NumericPrecision,
                x.NumericScale,
                ColumnNameMap = x.ColumnName.ToPascalCase(),
                TypeName      = SqlTypeMap.ContainsKey(x.DataType) ? SqlTypeMap[x.DataType] : x.DataType,
                IsNull        = x.IsNullable == "YES" && NullableTypes.Contains(SqlTypeMap.ContainsKey(x.DataType) ? SqlTypeMap[x.DataType] : x.DataType),
                Key           = table.TableConstraints.FirstOrDefault(y => y.ConstraintType == "PRIMARY KEY").
                                KeyColumnUsages.FirstOrDefault(y => y.ColumnName == x.ColumnName)
            });

            var classTemplate = File.ReadAllText(@"Template/ClassTemplate.Scriban");

            return(_templateService.Render(classTemplate, new
            {
                columns,
                table.TableName,
                TableNameMap = table.TableName.ToPascalCase()
            }));
        }
Ejemplo n.º 2
0
        public static string ToSQLType(this Type type)
        {
            string sqlType = $"varchar({int.MaxValue})";

            if (SqlTypeMap.ContainsKey(type))
            {
                sqlType = SqlTypeMap[type];
            }

            if ((type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable <>)) ||
                !type.IsValueType)
            {
                sqlType = $"{sqlType} NULL";
            }
            else
            {
                sqlType = $"{sqlType} NOT NULL";
            }

            return(sqlType);
        }