CodeSmith Model:

<%--

Name: CodeSmith Model

Date Time:<%=DateTime.Now.ToString()%>

Author: chhuic 2009-08-30 QQ:418715961 E_MAIL:

Description: CodeSmith Model

--%>

<%@ CodeTemplate Language="C#" TargetLanguage="C#"

Description="Generates a class including a special informational header" %>

<%@ Property Name="NameSpace" Type="String"

Category="Context"

Description="The namespace to use for this class" %>

<%@ Property Name="ClassName" Type="String"

Category="Context"

Description="The name of the class to generate" %>

<%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Category="Context" Description="Table that the stored procedures should be based on." %>

<%@ Assembly Name="SchemaExplorer" %>

<%@ Import Namespace="SchemaExplorer" %>

<script runat="template">

public string CSharpType(ColumnSchema column)

{

if (column.Name.EndsWith("TypeCode")) return column.Name;

switch (column.DataType)

{

case DbType.AnsiString: return "string ";

case DbType.AnsiStringFixedLength: return "string ";

case DbType.Binary: return "byte[] ";

case DbType.Boolean: return "bool ";

case DbType.Byte: return "byte ";

case DbType.Currency: return "decimal ";

case DbType.Date: return "DateTime";

case DbType.DateTime: return "DateTime";

case DbType.Decimal: return "decimal ";

case DbType.Double: return "double ";

case DbType.Guid: return "Guid ";

case DbType.Int16: return "short ";

case DbType.Int32: return "int ";

case DbType.Int64: return "long ";

case DbType.Object: return "object ";

case DbType.SByte: return "sbyte ";

case DbType.Single: return "float ";

case DbType.String: return "string ";

case DbType.StringFixedLength: return "string ";

case DbType.Time: return "TimeSpan";

case DbType.UInt16: return "ushort ";

case DbType.UInt32: return "uint ";

case DbType.UInt64: return "ulong ";

case DbType.VarNumeric: return "decimal ";

default:

{

return "__UNKNOWN__" + column.NativeType;

}

}

}

</script>

///////////////////////////////////////////////////////////////////////////////////////

// File: <%=SourceTable.Name %>Model.cs

// Description: the <%=SourceTable.Name %>Model Created By CodeSmith.

// ------

// Copyright: @ <%= DateTime.Now %>

// ------

// History:

///////////////////////////////////////////////////////////////////////////////////////

using System;

namespace <%=NameSpace%>.<%=ClassName%>

{

/// <summary>

/// Summary description for <%=SourceTable.Name %>Model.

/// Description:<%=SourceTable.Description %>

/// </summary>

public class <%=SourceTable.Name %>Model

{

#region Private Protery

<%for(int i=0;i<SourceTable.Columns.Count;i++){%>

private <%=CSharpType(SourceTable.Columns[i])%> _<%=SourceTable.Columns[i].Name.Substring(0,1).ToLower()+SourceTable.Columns[i].Name.Substring(1,SourceTable.Columns[i].Name.Length-1)%>;

<%}%>

#endregion

#region Constructor

/// <summary>

/// <%=SourceTable.Name %>Struct Constructor

/// </summary>

public <%=SourceTable.Name %>Model()

{

}

/// <summary>

/// <%=SourceTable.Name %>Struct Constructor(Have Parameters)

/// </summary>

<%for(int i=0;i<SourceTable.Columns.Count;i++){%>

///<param name="<%=SourceTable.Columns[i].Name.Substring(0,1).ToLower()+SourceTable.Columns[i].Name.Substring(1,SourceTable.Columns[i].Name.Length-1)%>"<%if(SourceTable.Columns[i].Description.Length>0){%<%=SourceTable.Columns[i].Name+" "+SourceTable.Columns[i].Description%<%}else{%<%=SourceTable.Columns[i].Name%<%}%</param>

<%}%>

public <%=SourceTable.Name %>Model(<%for(int i=0;i<SourceTable.Columns.Count;i++){%<%=CSharpType(SourceTable.Columns[i]).Trim()%> <%=SourceTable.Columns[i].Name.Substring(0,1).ToLower()+SourceTable.Columns[i].Name.Substring(1,SourceTable.Columns[i].Name.Length-1)%<% if (i < SourceTable.Columns.Count - 1) { %>,<%}%<%}%>)

{

<%for(int i=0;i<SourceTable.Columns.Count;i++){%>

this._<%=SourceTable.Columns[i].Name.Substring(0,1).ToLower()+SourceTable.Columns[i].Name.Substring(1,SourceTable.Columns[i].Name.Length-1)%> = <%=SourceTable.Columns[i].Name.Substring(0,1).ToLower()+SourceTable.Columns[i].Name.Substring(1,SourceTable.Columns[i].Name.Length-1)%>;

<%}%>

}

#endregion

#region public Property

<%for(int i=0;i<SourceTable.Columns.Count;i++){%>

///<Summary>

/// <%=SourceTable.Columns[i].Name%<%if(SourceTable.Columns[i].Description.Length>0){%>

/// <%=SourceTable.Columns[i].Description%<%}%>

///</Summary>

public <%=CSharpType(SourceTable.Columns[i]).Trim()%> <%=SourceTable.Columns[i].Name%>

{

get { return _<%=SourceTable.Columns[i].Name.Substring(0,1).ToLower()+SourceTable.Columns[i].Name.Substring(1,SourceTable.Columns[i].Name.Length-1)%>; }

set { _<%=SourceTable.Columns[i].Name.Substring(0,1).ToLower()+SourceTable.Columns[i].Name.Substring(1,SourceTable.Columns[i].Name.Length-1)%> = value; }

}

<%}%>

#endregion

}

}