在CodeSmith里要建立一个数据源,在CodeSmith里有一个Schema Explooer,如下图:
通过它可以访问数据库的表结构。在Schema Explooer上有个ManageDataSourse的图标,点击他会出现以下的界面:
点击ADD按钮,出现以下的界面:
输入Name:gj,支持的类型我们选择Sql..,再输入链接数据库的字符串:server=.;uid=sa;pwd=;database=bsee
之后我们就可以浏览数据库BSEE里的表了。
我们继续将CodeSmith属性,还是老样看下一段代码:
<%@ CodeTemplate Language="C#" TargetLanguage="C#"
Description="Generates a class including a special informational header" %>
<%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema"
Category="Context"
Description="Table that the stored procedures should be based on." %>
<%@ Assembly Name="SchemaExplorer" %>
首先我们看:<%@ Assembly Name="SchemaExplorer" %>。这是一个引用程序集的方式,所有的.NET的程序集都可以通过这些方式引用到CodeSmith使用。Description="Generates a class including a special informational header" %>
<%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema"
Category="Context"
Description="Table that the stored procedures should be based on." %>
<%@ Assembly Name="SchemaExplorer" %>
之后我们声明一个属性SourceTable,他的Type设置为SchemaExplorer.TableSchema,这样我们就可以通过这种方式访问我们特定的数据库的表了。运行之后结果如下
:
点击浏览:
明天们将接着将怎样利用访问到的数据表生成我们想要的东东。