首先在使用之前,先要下载 OracleNativeSchemaProvider

之后需要需要在数据库建一个表,如果不建这个表的话,在使用Description的属性时会报错

create   table   codesmith_extended_properties 
( 
    container_object_owner   varchar2(50)   not   null, 
    object_name                         varchar2(61)   not   null, 
    codesmith_schema_type     varchar2(200)   not   null, 
    property_name                     varchar2(75)   not   null, 
    property_value                   varchar2(4000)   not   null, 
    clr_type                               varchar2(50)   not   null 
)

 

下面是模板,根据不同需求编写,这个是最基础的实体生成,当然,没有100%不用修改的模板

 

<%@ CodeTemplate Language="C#" TargetLanguage="C#" ResponseEncoding="UTF-8" Description="Create Normal Object" %>
<%@ Property Name="DeveloperName" Type="String" Category="Context" Default="" Description="Creator" %>
<%@ Property Name="NameSpace" Type="String" Category="Context" Default="" Description="Namespace" %>
<%@ Property Name="SourceTable" Type="SchemaExplorer.TableSchema" Category="Context" Description="Table which will be Build" %>
<%@ Assembly Name="SchemaExplorer" %>
<%@ Assembly Name="System.Data" %>
<%@ Import Namespace="SchemaExplorer" %>
<%@ Import Namespace="System.Data" %>
using System;
using System.Collections.Generic;
using System.Text;
namespace <%= NameSpace %>
{
    /// <summary>
    ///     创 建 人: <%= DeveloperName %>
    ///     创建日期: <%= DateTime.Now.Date.ToString("yyyy-MM-dd")%>
    ///     文件描述: <%= SourceTable.Name %> 表对应实体
    /// </summary>
    public class <%= SourceTable.Name %> : NeuObject
    {
        #region 私有变量
        <% foreach (ColumnSchema column in SourceTable.Columns)
{
%>
        /// <summary>
        /// <%= column.Description.ToString()%>
        /// </summary>
        private <%= column.DataType %> m_<%= column.Name %>;
<%
}
%>
        #endregion
        #region 属性
<% foreach (ColumnSchema column in SourceTable.Columns)
{
%>
        /// <summary>
        /// <%= column.Description.ToString()%>
        /// </summary>
        public <%= column.DataType%> <%= column.Name %>
        {
            get{ return m_<%= column.Name%>; }
            set{ m_<%= column.Name%> = value; }
        }
<%
}
%>
        #endregion
        #region 克隆
        /// <summary>
        /// 克隆方法
        /// </summary>
        public new <%= SourceTable.Name %> Clone()
        {
            <%= SourceTable.Name %> obj = base.Clone() as <%= SourceTable.Name %>;
            return obj;
        }
        #endregion
}
}
 
基本上所有的实体都会通过表来生成。

 

很久没写模板了,貌似现在的公司,也不强制要求固定的格式,呵呵,尽兴吧。~

 

陆续会总结一些现在比较常用的form的模板,能生成还是生成吧,我宁愿改,也不想当代码工人。

 

顺带一句,我的大段注释,一般都是用CodeSmith的模板生成的,今天在园子里看到一篇VS的使用技巧,才知道,原来注释是可以直接拖进工具栏,以备经常使用的,很好,很强大。

posted on 2010-03-30 09:02  C.Gavin  阅读(763)  评论(0编辑  收藏  举报