用CodeSmith生成数据库字典

<%@ CodeTemplate Language="C#" TargetLanguage="text" ResponseEncoding="UTF-8" Description="Generates a update stored procedure." %>
<%@ Property Name="SourceDatabase" Type="SchemaExplorer.DatabaseSchema" Category="Context" Description="Database that the documentation should be based on." %>
<%@ Property Name="Author" Type="System.String" Default="Pantao" Optional="False" Category="Description" Description="About Author" %>
<%@ Assembly Name="SchemaExplorer" %>
<%@ Import Namespace="SchemaExplorer" %>
<script runat="template">
public string GetSqlParameterStatement(ColumnSchema column)
{
string param = "";

switch (column.DataType)
{
case DbType.Decimal:
{
param += "(" + column.Precision + ", " + column.Scale + ")";
break;
}
case DbType.Boolean:
case DbType.Int32:
case DbType.DateTime:
case DbType.Double:
case DbType.Single:
case DbType.Byte:
case DbType.Int64:
case DbType.Int16:

break;
default:
{
if (column.Size > 0)
{
param += "(" + column.Size + ")";
}
break;
}
}

return param;
}
</script>
<% TableSchemaCollection tables = new TableSchemaCollection(SourceDatabase.Tables); %>
数据库字典(总表数:<% =tables.Count.ToString() %>)
作者:<% =Author %> 时间:<% =DateTime.Now.ToShortDateString() + " " + DateTime.Now.ToShortTimeString() %>
<% for(int i=0; i<tables.Count; i++) { %>

<% =i + 1 + "." %>表名:【<% =tables[i].Name %>】
<% for(int k=0; k<tables[i].Columns.Count; k++) { %>
<% =tables[i].Columns[k].Name %> <% if (tables[i].Columns[k].IsPrimaryKeyMember) {%>Primary<% } %> <% =tables[i].Columns[k].NativeType + GetSqlParameterStatement(tables[i].Columns[k]) %> <% if(tables[i].Columns[k].AllowDBNull) { %>AllowNull<% } %>
<% ="〖描述:〗" + tables[i].Columns[k].Description %>
<% } %>
<% } %>

你可能感兴趣的:(C++,c,C#)