生成数据表实体类 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>
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>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 25岁的心里话
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现