<%-- 
Name Enrity Class:
Author JunFenglai: 
Description: This is a simple Template.
--%>
<%@ CodeTemplate Language="C#" TargetLanguage="C#"  Src="" ResponseEncoding="UTF-8" Inherits="" Debug="False" Description="This is a simple Template." %>
<%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Category="Context" Description="Table that the object is based on." %>
<%@ Import Namespace="SchemaExplorer" %>
<%@ Import Namespace="System.Data" %>
<%@ Assembly Name="SchemaExplorer" %>
<%@ Assembly Name="System.Data" %>
using System;namespace Feng_Model
{
/// <summary>
/// <%=SourceTable.Description%>
/// </summary>
public class <%= SourceTable.Name %>
{
<%= GetProperties(SourceTable)%>
}
}
<script runat="template">
public string GetPrimaryKeyType(TableSchema table)
{
if (table.PrimaryKey != null)
{
return table.Columns[0].NativeType;
}
else
{
throw new ApplicationException("This template will only work on tables with a primary key.");
}
}
public string GetProperties(TableSchema table)
{
string content="";
foreach(ColumnSchema var in table.Columns)
{
content +="private "+GetCSharpVariableType(var)+" "+ToField(var.Name)+";\r\n";
content +="\t\t/// <summary>\r\n";
content +="\t\t/// "+var.Description+"\r\n";
content +="\t\t/// </summary>\r\n";
content +="\t\tpublic "+GetCSharpVariableType(var)+" "+ToProperty(var.Name)+"\r\n";
content +="\t\t{\r\n";
content +="\t\t\tget{ return "+ToField(var.Name)+"; }\r\n";
content +="\t\t\tset{ "+ToField(var.Name)+" = value; }\r\n";
content +="\t\t}\r\n\r\n\t\t";
}
return content;
}public string GetCSharpVariableType(ColumnSchema column)
{
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;
}
}
}public string ToField(string field)
{
return field.Substring(0, 1).ToLower() + field.Substring(1, field.Length-1);
}
public string ToProperty(string field)
{
return field.Substring(0, 1).ToUpper() + field.Substring(1, field.Length-1);
}public override string GetFileName()
{
return this.SourceTable.Name+".cs";
}
</script>