CodeSmith实体类模板
Code
<%--
Name:Model
Author:吕艳阳
Description: 生成实体Model
--%>
<%@ CodeTemplate Language="C#" TargetLanguage="C#" Debug="False" Description="生成Model类." ResponseEncoding="UTF-8" %>
<%@ Assembly Name="System.Data" %>
<%@ Assembly Name="SchemaExplorer" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="SchemaExplorer" %>
<%@ Map Name="CSharpAlias" Src="System-CSharpAlias" Description="" %>
<%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Category="参数" Description="表名称" %>
<%@ Property Name="NameSpace" Type="String" Category="参数" Description="命名空间" Default="ChinaSoft.Model" Optional="True"%>
using System;
namespace <%=NameSpace%>
{
/// <summary>
/// <%=SourceTable.Description%>(<%=SourceTable.Name%>)实体类
/// </summary>
public class <%=SourceTable.Name%>
{
/// <summary>
/// <%=SourceTable.Description%>(<%=SourceTable.Name%>)实体类
/// </summary>
public <%=SourceTable.Name%>()
{
}
/// <summary>
/// <%=SourceTable.Description%>(<%=SourceTable.Name%>)实体类
/// </summary>
<% foreach (ColumnSchema column in SourceTable.Columns) { %>
/// <param name="<%=column.Name.ToLower()%>"><%= column.Description %></param>
<% } %>
public <%=SourceTable.Name%>(<%
System.Text.StringBuilder builder = new System.Text.StringBuilder();
for(int i=0;i<SourceTable.Columns.Count;i++)
{
ColumnSchema column = SourceTable.Columns[i];
builder.Append(CSharpAlias[column.SystemType.FullName]);
builder.Append(" ");
builder.Append(column.Name.ToLower());
if(i!=SourceTable.Columns.Count-1)
{
builder.Append(",");
}
}
Response.Write(builder.ToString());
%>)
{
<% foreach (ColumnSchema column in SourceTable.Columns) { %>
this.<%=StringUtil.ToPascalCase(column.Name)%> = column.Name.ToLower();
<% } %>
}
#region Model
<% foreach (ColumnSchema column in SourceTable.Columns) { %>
private <%=CSharpAlias[column.SystemType.FullName]%> _<%= column.Name.ToLower()%>;
<% } %>
<% foreach (ColumnSchema column in SourceTable.Columns) { %>
/// <summary>
/// <%= column.Description %>
/// </summary>
public <%=CSharpAlias[column.SystemType.FullName]%> <%= StringUtil.ToPascalCase(column.Name)%>
{
set { _<%= column.Name.ToLower()%> = value; }
get { return _<%= column.Name.ToLower()%>; }
}
<% } %>
#endregion Model
}
}