CodeSmithJames/EntityLayer/EntityLayer.cst <%-- Name:实体层的代码生成器. Author: DENG YULIN --%> <%--TargetLanguage决定哪些是关键字.如,对于C#,using是关键字;对于T-SQL,CREATE是关键字--%> <%@ CodeTemplate Language="C#" Src="../CommonSqlCode.cs" Inherits="MoM.Templates.CommonSqlCode" ResponseEncoding="UTF-8" TargetLanguage="C#" Description="实体层的代码生成器." %> <%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Category="DataSource" Description="Table that the entity layer class should be based on." %> <%-- 节点Namespaces --%> <%@ Property Name="NameSpace" Default="James" Optional="False" Type="System.String" Category="Namespaces" Description="The namespace to use for these classes." %> <%-- 节点UserInfo--%> <%@ Property Name="YourName" Type="System.String" Default="James" Optional="False" Category="UserInfo" Description="User Name." %> <%@ Assembly Name="SchemaExplorer" %> <%@ Import Namespace="SchemaExplorer" %> <% string EntityclassName = GetClassName(SourceTable.Name) + "Attribute"; %> using System; using System.Collections.Generic; using System.Text; ///Date Created: <%= DateTime.Now.ToLongDateString() %> ///Created By: Generated by <% if (YourName.Length > 0) {Response.Write(YourName);} else {Response.Write("James");}%> namespace <%= NameSpace %> { /// 属性类/实体类 <%= EntityclassName %> public class <%= EntityclassName %> { //定义私有成员 <% for (int i = 0; i < SourceTable.Columns.Count; i++) { %> private <%= ConvertDBTypeToCSType(SourceTable.Columns[i]) %> <%= GetPrivateNameInClass( SourceTable.Columns[i].Name) %>; <% } %> //构造函数 public <%= EntityclassName %>() { } //构造函数的重载 public <% = EntityclassName %> ( <% for (int i = 0; i < SourceTable.Columns.Count; i++) { %> <%= ConvertDBTypeToCSType(SourceTable.Columns[i]) %> <%= GetRefNameInFunction( SourceTable.Columns[i].Name) %><% if( i != SourceTable.Columns.Count - 1) Response.Write(","); %> <% } %> ) { <% for (int i = 0; i < SourceTable.Columns.Count; i++) { %> this.<%= GetPrivateNameInClass( SourceTable.Columns[i].Name) %> = <%= GetRefNameInFunction( SourceTable.Columns[i].Name) %>; <% } %> } //定义属性成员 <% for (int i = 0; i < SourceTable.Columns.Count; i++) { %> public <%= ConvertDBTypeToCSType(SourceTable.Columns[i]) %> <%= GetPublicNameInClass( SourceTable.Columns[i].Name) %> { get{ return <%= GetPrivateNameInClass( SourceTable.Columns[i].Name) %>; } set{ this.<%= GetPrivateNameInClass( SourceTable.Columns[i].Name) %> = value; } } <%} %> } } <mce:script runat="template"><!-- // --></mce:script>