<%@ CodeTemplate Language="C#" TargetLanguage="Text" Src="" Inherits="" Debug="False" Description="Template description here." %>
<%@ Property Name="SampleStringProperty" Type="System.String" Default="SomeValue" Optional="True" Category="Strings" Description="This is a sample string property." %>
<%@ Property Name="SampleBooleanProperty" Type="System.Boolean" Default="True" Optional="False" Category="Booleans" Description="This is a sample boolean property." %>
<%@ Assembly Name="System.Data" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Property Name="nameSpace" Type="String" Default="Book" Optional="False" Category="" Description="" OnChanged="" Editor="" EditorBase="" Serializer="" %>
<%@ Assembly Name="SchemaExplorer" %>
<%@ Import Namespace="SchemaExplorer" %>
<%@ Property Name="DataBaseSource" Type="SchemaExplorer.DatabaseSchema" Category="Context" Description="" %>
<%@ Property Name="index" Type="System.Int32" Default="1" Optional="False" Category="" Description="" OnChanged="" Editor="" EditorBase="" Serializer="" %>
<%@ Import Namespace="System.IO" %>
///??:jiedamu
///??:<%=DateTime.Now.ToShortDateString() %>
///??:???<%= StringUtil.ToPascalCase(DataBaseSource.Tables[index].Name) %>
using System;
using System.Data.Common;
using System.Collections.Generic;
using System.Text;
namespace Model
{
public class <%= StringUtil.ToPascalCase(DataBaseSource.Tables[index].Name) %>
{
<%
//?????????????
foreach(ColumnSchema col in DataBaseSource.Tables[index].Columns)
{
%>
<%-- ???? --%>
private <%=GetType(col.DataType) %> <%=StringUtil.ToCamelCase(col.Name) %>;
<%-- ???? --%>
public <%=GetType(col.DataType) %> <%=StringUtil.ToPascalCase(col.Name) %>
{
set { this.<%=StringUtil.ToCamelCase(col.Name) %> = value; }
get { return this.<%=StringUtil.ToCamelCase(col.Name) %>; }
}
<%
}
%>
}
}
<script runat="template">
public string GetType(System.Data.DbType dbType)
{
switch (dbType)
{
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 "DateTime";
case DbType.UInt16:
return "ushort";
case DbType.UInt32:
return "uint";
case DbType.UInt64:
return "ulong";
case DbType.VarNumeric:
return "decimal";
case DbType.Xml:
return "string";
default:
return "object";
}
}
public override void Render(TextWriter writer)
{
string path1 =OutputDirectory + StringUtil.ToPascalCase(DataBaseSource.Tables[index].Name) + ".cs";
System.Diagnostics.Trace.WriteLine(path1);
StreamWriter fileWriter1 = new StreamWriter(path1,false);
this.Response.AddTextWriter(fileWriter1);
base.Render(writer);
fileWriter1.Close();
}
private string _outputDirectory = String.Empty;
[Editor(typeof(System.Windows.Forms.Design.FolderNameEditor), typeof(System.Drawing.Design.UITypeEditor))]
[Optional]
[Category("Output")]
[Description("The directory to output the results to.")]
public string OutputDirectory
{
get
{
// default to the directory that the template is located in
if (_outputDirectory.Length == 0) return this.CodeTemplateInfo.DirectoryName;
return _outputDirectory;
}
set
{
if (!value.EndsWith("//")) value += "//";
_outputDirectory = value;
}
}
</script>
联系客服