protected void GenerateTableInDbClass(StringBuilder sb, SqlTable table) { // TODO move to table class declaration 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); } var tableName = Helper.GetSimplifiedSchemaAndTableName(table.SchemaAndTableName, DatabaseDeclaration.SchemaTableNameSeparator.ToString(CultureInfo.InvariantCulture)); sb .Append(2, "public ") .Append(tableName) .Append("Table") .Append(' ') .Append(tableName) .Append(" { get; } = new ") .Append(tableName) .Append("Table") .AppendLine("();"); // GenerateTableProperties(sb, table); }
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, "});"); }