生成数据表实体类 for iBATIS.NET

 

 Filename: EntityClass.cst

<%--  
  Code Generator 
for  iBATIS.NET  1.2 . 1
  功能描述: 生成数据表实体类
  Modify Log:
      
2005 / 11 / 03   增加表名到类名的重命名功能
--%>
<% @ CodeTemplate Language = " C# "  TargetLanguage = " C# "  LinePragmas = " True "   %>
<% @ Assembly Name = " SchemaExplorer "   %>
<% @ Import Namespace = " SchemaExplorer "   %>
<% @ Property Name = " SourceTable "  Type = " SchemaExplorer.TableSchema "  Category = " DataSource "  
            Description
= " 选择一个数据表 "   %>
<% @ Property Name = " TableRename "  Type = " String "  Category = " DataSource "  
            Description
= " 如果不需要表名到类名的重命名, 请保留空 "   %>
<% @ Property Name = " Namespace "  Type = " String "  Category = " Main "  
            Description
= " 输出的实体类的命名空间 "   %>
<% @ Property Name = " Developer "  Type = " String "  Category = " Main "  
            Description
= " 作者 "   %>
// ***********************************************************************
//   Created: <%= DateTime.Now.ToShortDateString() %>    Author:  <%= Developer %>
//   File: <%= ClassName %>.cs
//   Description: 数据表 <%= TableName %> 的实体类, 使用 CodeSmith 自动生成.
// ***********************************************************************
using  System;
using  System.Collections;

namespace   <%=  Namespace  %>
{
    
///   <summary>
    
///   <%= ClassName %>  class description here.
    
///   </summary>
     public   class   <%=  ClassName  %>
    {
        
        
#region  Properties
        
<%   for  ( int  i = 0 ; i < SourceTable.Columns.Count; i ++ %>
        
<%  {  %>
        
<%   string  colName    =  SourceTable.Columns[i].Name.ToString();  %>
        
<%   string  colLength  =  SourceTable.Columns[i].Size.ToString();  %>
        
<%   string  colType  =  SourceTable.Columns[i].SystemType.ToString();  %>
        
<%   string  colDBType    =  SourceTable.Columns[i].NativeType.ToString();  %>
        
///   <summary>
        
///  字段: <%= colName %>
        
///  长度: <%= colLength %>
        
///  类型: <%= colDBType %>
        
///   </summary>
         private   <%=  colType  %>  _ <%=  colName  %> ;
        
public   <%=  colType  %>    <%=  colName  %>
        {
            
get  {  return  _ <%=  colName  %> ; }
            
set  { _ <%=  colName  %>   =  value; }
        }
        
        
<%  }  %>
        
#endregion
        
        
        
#region  Constructure
        
///   <summary>
        
///  构造函数
        
///   </summary>
         public   <%=  ClassName  %> ()
        {
            
//
            
//  TODO: <%= ClassName %> constructure logic
            
//
        }
        
#endregion
        
        
        
#region  Methods
        
///   <summary>
        
///  增加记录
        
///   </summary>
         public   static   int  Add( <%=  ClassName  %>  _ <%=  ClassName  %> )
        {
            
return  ( int )Mapper().Insert( " <%= ClassName %>.insert " , _ <%=  ClassName  %> );
        }
        
        
///   <summary>
        
///  更新记录
        
///   </summary>
         public   static   int  Update( <%=  ClassName  %>  _ <%=  ClassName  %> )
        {
            
return  Mapper().Update( " <%= ClassName %>.update " , _ <%=  ClassName  %> );
        }
        
        
///   <summary>
        
///  删除记录
        
///   </summary>
         public   static   int  Delete( string  recordID)
        {
            
return  Mapper().Delete( " <%= ClassName %>.delete " , recordID);
        }
        
        
///   <summary>
        
///  选择记录(一条)
        
///   </summary>
         public   static   <%=  ClassName  %>  Select( string  recordID)
        {
            
return  (Mapper().QueryForObject( " <%= ClassName %>.select " , recordID)  as   <%=  ClassName  %> );
        }
        
        
///   <summary>
        
///  选择记录(所有)
        
///   </summary>
         public   static  IList SelectAll()
        {
            
return  Mapper().QueryForList( " <%= ClassName %>.selectAll " null );
        }
        
#endregion
        
        
        
#region  HelpMethod
        
///   <summary>
        
///  返回Mapper
        
///   </summary>
         public   static  IBatisNet.DataMapper.SqlMapper Mapper()
        {
            
return  IBatisNet.DataMapper.Mapper.Instance();
        }
        
#endregion
        
        
    }
}
< script runat = " template " >
    
///   <summary>
    
///  输出的类名
    
///   </summary>
     private   string  ClassName
    {
        
get
        {
            
return  TableRename.Trim().Length  ==   0   ?   " SourceTable.Name "  : TableRename.Trim();
        }
    }
    
    
///   <summary>
    
///  输入的数据表名
    
///   </summary>
     private   string  TableName
    {
        
get
        {
            
return  SourceTable.Name;
        }
    }
</ script >

你可能感兴趣的:(ibatis)