private void AppendFullTemplate(StringBuilder sb, Table table, ModelRoot model)
{
try
{
var moduleSuffix = string.Empty;
if (!string.IsNullOrEmpty(_model.ModuleName))
moduleSuffix = _model.ModuleName + "_";
sb.AppendLine("if exists(select * from sys.objects where name = '" + GetStoredProcedureName(table, model, moduleSuffix) + "' and type = 'P' and type_desc = 'SQL_STORED_PROCEDURE')");
sb.AppendLine(" drop procedure [" + table.GetSQLSchema() + "].[" + GetStoredProcedureName(table, model, moduleSuffix) + "]");
sb.AppendLine("GO");
sb.AppendLine();
//Just drop the procedure if no CRUD SP
if (!_model.Database.UseGeneratedCRUD)
return;
sb.AppendLine("CREATE PROCEDURE [" + table.GetSQLSchema() + "].[" + GetStoredProcedureName(table, model, moduleSuffix) + "]");
sb.AppendLine("(");
sb.AppendLine(BuildParameterList(table, model));
sb.AppendLine(")");
sb.AppendLine("AS");
sb.AppendLine("SET NOCOUNT OFF;");
sb.AppendLine();
sb.Append(SQLGeneratedBodyHelper.SQLInsertBusinessObjectBody(table, model));
sb.AppendLine("GO");
sb.AppendLine();
if (model.Database.GrantExecUser != string.Empty)
{
sb.AppendFormat("GRANT EXECUTE ON [" + table.GetSQLSchema() + "].[{0}] TO [{1}]", GetStoredProcedureName(table, model, moduleSuffix), model.Database.GrantExecUser).AppendLine();
sb.AppendLine("GO");
sb.AppendLine();
}
}
catch (Exception ex)
{
throw;
}
}