用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 %>
 <% } %>
<% } %> 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值