本文整理汇总了C#中StoredProcedure.ScriptHeader方法的典型用法代码示例。如果您正苦于以下问题:C# StoredProcedure.ScriptHeader方法的具体用法?C# StoredProcedure.ScriptHeader怎么用?C# StoredProcedure.ScriptHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StoredProcedure
的用法示例。
在下文中一共展示了StoredProcedure.ScriptHeader方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: generate
public void generate(string path, ProcedureGenerationType type, bool justGenerateScriptFiles)
{
#region [ Validate object state for generation. ]
if (_database == null || _table == null)
{
return;
}
#endregion
#region [ Set the procedure's name. ]
string procedureName = string.Format("cp_{0}", _table.Name);
#endregion
#region [ Create the procedure object. ]
StoredProcedure procedure = new StoredProcedure(_database, procedureName);
procedure.Schema = _table.Schema;
#endregion
#region [ Set the procedure's parameters. ]
procedure.TextMode = false;
StoredProcedureParameter operationParameter = new StoredProcedureParameter(procedure, "@Operation");
operationParameter.DataType = DataType.Int;
operationParameter.DefaultValue = "0";
procedure.Parameters.Add(operationParameter);
StoredProcedureParameter userParameter = new StoredProcedureParameter(procedure, "@User");
userParameter.DataType = DataType.NVarChar(128);
userParameter.DefaultValue = "NULL";
procedure.Parameters.Add(userParameter);
IDictionary<Column, StoredProcedureParameter> columnsToParameters = new SortedDictionary<Column, StoredProcedureParameter>(new ColumnComparer());
foreach (Column column in _table.Columns)
{
StoredProcedureParameter parameter = new StoredProcedureParameter(procedure, string.Format("@{0}", column.Name));
parameter.DataType = column.DataType;
parameter.DefaultValue = string.IsNullOrEmpty(column.Default) ? "NULL" : column.Default;
columnsToParameters.Add(column, parameter);
procedure.Parameters.Add(parameter);
}
#endregion
#region [ Set the procedure's header. ]
string textHeader = procedure.ScriptHeader(true);
#region [ Sort and format the parameters for readability ]
// Split the procedure's parameters by line
string[] parameters = textHeader.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
// Create a line to hold each parameter's: name, data type,
// and default value.
string[][] parameterParts = new string[parameters.Length - 2][];
for (int l = 0; l < parameterParts.Length; l++)
{
parameterParts[l] = new string[3];
}
// Create a regular expression to split the parameter into
// its parts.
Regex regex = new Regex("(\\s)*(@[^\\s]+)\\s+(\\[.*\\](\\s*\\([^\\(]*\\)){0,1})\\s*([^,]*)(,)*(.*)");
// Determine the maximum length of parameter name and data
// type for formatting.
int parameterNameSize = 0;
int parameterTypeSize = 0;
for (int i = 1; i < parameters.Length - 1; i++)
{
string parameter = parameters[i];
Match match = regex.Match(parameter);
if (match.Groups[2].Value.Length > parameterNameSize)
{
parameterNameSize = match.Groups[2].Value.Length;
}
if (match.Groups[3].Value.Length > parameterTypeSize)
{
parameterTypeSize = match.Groups[3].Value.Length;
}
}
// Sort and format (align) the parameters.
SortedDictionary<string, string[]> sortedParameters = new SortedDictionary<string, string[]>();
for (int j = 1; j < parameters.Length - 1; j++)
{
string parameter = parameters[j];
Match match = regex.Match(parameter);
parameterParts[j - 1][0] =
match.Groups[1].Value +
(j == 1 ? " " : ",") +
match.Groups[2].Value
.PadRight(parameterNameSize + 1);
//.........这里部分代码省略.........
示例2: Format
public string Format(StoredProcedure sproc)
{
var server = sproc.CreateWrapper();
var values = new Dictionary<string, object>(StringComparer.InvariantCultureIgnoreCase)
{
{ Const.Catalog, sproc.Parent.Name },
{ Const.Schema, sproc.Schema },
{ Const.Name, sproc.Name },
{ Const.NameEscaped, sproc.Name.EscapeName() },
{ Const.Body, sproc.TextBody.NormalizeSprocBody() },
{ Const.Header, sproc.ScriptHeader(true) },
{ Const.Needs, GetNeeds(server, sproc, DatabaseObjectTypes.StoredProcedure | DatabaseObjectTypes.UserDefinedFunction | DatabaseObjectTypes.View) ?? string.Empty }
};
values["parameters"] = string.Join(", ", sproc.Parameters.Cast<StoredProcedureParameter>().ToList().Select(p => p.Name + " = "));
return Const.Script.Sproc.Format().With(values);
}