利用CodeSmith为SQL Server CE生成项目代码
[08-08 00:48:39] 来源:http://www.xuehuiba.com 移动WAP开发 阅读:8187次
概要:TableProperties.cstCode highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><%-- Name: Database Table PropertiesAuthor: Paul WelterDescription: Create a list of properties from a database table--%><%@ CodeTemplate Language="C#" TargetLanguage="C#" Debug="False" Description="Create a list of properties from database table." %><%@ Property Name="SourceTable&q
利用CodeSmith为SQL Server CE生成项目代码,标签:移动WAP开发教程,wap网站开发,http://www.xuehuiba.com
TableProperties.cst
<%--
Name: Database Table Properties
Author: Paul Welter
Description: Create a list of properties from a database table
--%>
<%@ CodeTemplate Language="C#" TargetLanguage="C#" Debug="False" Description="Create a list of properties from database table." %>
<%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Category="Context" Description="Table that the object is based on." %>
<%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %>
<%@ Assembly Name="SchemaExplorer" %>
<%@ Import Namespace="SchemaExplorer" %>
<% foreach (ColumnSchema column in this.SourceTable.Columns) { %>
private <%= CSharpAlias[column.SystemType.FullName] %> _<%= StringUtil.ToCamelCase(column.Name) %>;
public <%= CSharpAlias[column.SystemType.FullName] %> <%= StringUtil.ToPascalCase(column.Name) %>
{
get { return _<%= StringUtil.ToCamelCase(column.Name) %>; }
set { _<%= StringUtil.ToCamelCase(column.Name) %> = value; }
}
<% } %>
private int _categoryID;
public int CategoryID
{
get { return _categoryID; }
set { _categoryID = value; }
}
private string _categoryName;
public string CategoryName
{
get { return _categoryName; }
set { _categoryName = value; }
}
private string _description;
public string Description
{
get { return _description; }
set { _description = value; }
TableProperties.cst
<%--
Name: Database Table Properties
Author: Paul Welter
Description: Create a list of properties from a database table
--%>
<%@ CodeTemplate Language="C#" TargetLanguage="C#" Debug="False" Description="Create a list of properties from database table." %>
<%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Category="Context" Description="Table that the object is based on." %>
<%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="System to C# Type Map" %>
<%@ Assembly Name="SchemaExplorer" %>
<%@ Import Namespace="SchemaExplorer" %>
<% foreach (ColumnSchema column in this.SourceTable.Columns) { %>
private <%= CSharpAlias[column.SystemType.FullName] %> _<%= StringUtil.ToCamelCase(column.Name) %>;
public <%= CSharpAlias[column.SystemType.FullName] %> <%= StringUtil.ToPascalCase(column.Name) %>
{
get { return _<%= StringUtil.ToCamelCase(column.Name) %>; }
set { _<%= StringUtil.ToCamelCase(column.Name) %> = value; }
}
<% } %>
模板被打开后,在CodeSmith右边停靠的Properties窗口选择SourceTable属性,点击旁边的“...”按钮浏览并选择一个Northwind.sdf数据库的表。这里我们选择Categories表,并点击Select按钮确定。
现在可以按F5生成代码了,生成的结果如下所示:
生成的代码private int _categoryID;
public int CategoryID
{
get { return _categoryID; }
set { _categoryID = value; }
}
private string _categoryName;
public string CategoryName
{
get { return _categoryName; }
set { _categoryName = value; }
}
private string _description;
public string Description
{
get { return _description; }
set { _description = value; }
Tag:移动WAP开发,移动WAP开发教程,wap网站开发,电脑知识学习 - 网页制作 - 移动WAP开发
上一篇:Android开发人员10大抱怨
最新更新