public string GetParentStoredProcedureName(Table table, ModelRoot model, string moduleSuffix) { if (table.ParentTable == null) return ""; else return model.GetStoredProcedurePrefix() + "_" + table.ParentTable.PascalName + "_" + moduleSuffix + "Insert"; }
public static string GetBody(Table table, ModelRoot model) { if (table.Immutable) return string.Empty; var sb = new StringBuilder(); sb.AppendLine("DELETE FROM"); sb.AppendLine(" [" + table.GetSQLSchema() + "].[" + Globals.GetTableDatabaseName(model, table) + "] "); sb.AppendLine("WHERE "); sb.AppendLine(" " + BuildDeleteWhereStatement(table, model) + ";"); sb.AppendLine(); sb.AppendLine("if (@@RowCount = 0) return;"); sb.AppendLine(); if (table.ParentTable != null) { var moduleName = (string.IsNullOrEmpty(model.ModuleName) ? string.Empty : "_" + model.ModuleName); sb.Append("exec [" + table.ParentTable.GetSQLSchema() + "].[" + model.GetStoredProcedurePrefix() + "_" + table.ParentTable.PascalName + moduleName + "_Delete]"); var pkIndex = 0; foreach (var column in table.PrimaryKeyColumns.OrderBy(x => x.Name)) { sb.Append(" @Original_" + column.ToDatabaseCodeIdentifier() + " = @Original_" + column.ToDatabaseCodeIdentifier()); pkIndex++; if (pkIndex < table.PrimaryKeyColumns.Count) sb.Append(","); } } sb.AppendLine(); return sb.ToString(); }
private string GetStoredProcedureName(Table table, ModelRoot model, string moduleSuffix) { return model.GetStoredProcedurePrefix() + "_" + table.PascalName + "_" + moduleSuffix + "Insert"; }