Пример #1
0
        protected override void GenerateTable(StringBuilder sb, SqlTable table)
        {
            var pks = table.Properties.OfType <PrimaryKey>().ToList();

            if (pks.Count == 0)
            {
                sb.AppendLine(2, "// no primary key");
            }

            var tableComment = OnTableComment?.Invoke(table);

            if (!string.IsNullOrEmpty(tableComment))
            {
                sb.Append(2, "// ").AppendLine(tableComment);
            }

            sb
            .Append(2, "public SqlTable ")
            .Append(Helper.GetSimplifiedSchemaAndTableName(table.SchemaAndTableName, DatabaseDeclaration.SchemaTableNameSeparator.ToString(CultureInfo.InvariantCulture)))
            .AppendLine(" { get; } = AddTable(table =>")
            .AppendLine(2, "{");

            var tableAnnotation = OnTableAnnotation?.Invoke(table);

            if (!string.IsNullOrEmpty(tableAnnotation))
            {
                sb.Append(3, "table").Append(tableAnnotation).AppendLine(";");
            }

            var pkColumns = table.Columns
                            .Where(column => column.Table.Properties.OfType <PrimaryKey>().Any(x => x.SqlColumns.Any(y => y.SqlColumn == column)))
                            .ToList();

            foreach (var column in pkColumns)
            {
                var columnAnnotation = OnColumnAnnotation?.Invoke(column);
                var columnComment    = OnColumnComment?.Invoke(column);

                var columnCreation = Writer.GetColumnCreation(column, Helper, columnAnnotation, columnComment);
                sb.AppendLine(columnCreation);
            }

            var regularColumns = table.Columns
                                 .Where(x => !pkColumns.Contains(x))
                                 .ToList();

            foreach (var column in regularColumns)
            {
                var columnAnnotation = OnColumnAnnotation?.Invoke(column);
                var columnComment    = OnColumnComment?.Invoke(column);

                var columnCreation = Writer.GetColumnCreation(column, Helper, columnAnnotation, columnComment);
                sb.AppendLine(columnCreation);
            }

            GenerateTableProperties(sb, table);
            sb.AppendLine(2, "});");
        }
Пример #2
0
        protected override void GenerateTable(StringBuilder sb, SqlTable table)
        {
            var tableName = Helper.GetSimplifiedSchemaAndTableName(table.SchemaAndTableName, DatabaseDeclaration.SchemaTableNameSeparator.ToString(CultureInfo.InvariantCulture));

            sb
            .Append(1, "public class ")
            .Append(tableName)
            .Append("Table")
            .AppendLine(" : SqlTable")
            .AppendLine(1, "{");

            var pkColumns = table.Columns
                            .Where(column => column.Table.Properties.OfType <PrimaryKey>().Any(x => x.SqlColumns.Any(y => y.SqlColumn == column)))
                            .ToList();

            foreach (var column in pkColumns)
            {
                var columnAnnotation = OnColumnAnnotation?.Invoke(column);
                var columnComment    = OnColumnComment?.Invoke(column);

                var columnCreation = Writer.GetColumnCreation(column, Helper, columnAnnotation, columnComment);
                sb.AppendLine(columnCreation);
            }

            var regularColumns = table.Columns
                                 .Where(x => !pkColumns.Contains(x))
                                 .ToList();

            foreach (var column in regularColumns)
            {
                var columnAnnotation = OnColumnAnnotation?.Invoke(column);
                var columnComment    = OnColumnComment?.Invoke(column);

                var columnCreation = Writer.GetColumnCreation(column, Helper, columnAnnotation, columnComment);
                sb.AppendLine(columnCreation);
            }

            GenerateTableProperties(sb, table);
            sb.AppendLine(1, "}");
        }