CodeSmith如何生成实体类 ,完善版

<%-- 
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" %>

[Table("<%=SourceTable.Name%>")]
public class <%= StringUtil.ToPascalCase(SourceTable.Name.TrimEnd('s')) %>
{

<% foreach (ColumnSchema column in this.SourceTable.Columns) {  %>
/// <summary>
/// <%= column.Description %>
/// </summary>
private <%= CSharpAlias[column.SystemType.FullName] %> _<%= StringUtil.ToCamelCase(column.Name) %>;
[Column("<%=column.Name%>")]
public <%= CSharpAlias[column.SystemType.FullName] %> <%= StringUtil.ToPascalCase(column.Name) %>
{
    get { return _<%= StringUtil.ToCamelCase(column.Name) %>; }
    set { _<%= StringUtil.ToCamelCase(column.Name) %> = value; }
}

<% } %>
public <%= StringUtil.ToPascalCase(SourceTable.Name.TrimEnd('s')) %>()
{
            
}
}

 

posted @ 2017-03-20 16:24  青山下  阅读(271)  评论(0编辑  收藏  举报