Models--自动生成实体层代码

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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值